2012-04-25 67 views
0
<?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
     xmlns:tns="http://tempuri.org/" 
     xmlns:types="http://tempuri.org/encodedTypes" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
      <soap:Header> 
       <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:mustUnderstand="1"> 
        <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="unt_PQxtsT0a8iV1KN2Y"> 
         <wsse:Username></wsse:Username> 
         <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"></wsse:Password> 
         <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">i03CXze0uiIYG8+q8MhEMYHiMcL/NOpCwvEVpQ5xo+M=</wsse:Nonce> 
         <wsu:Created>2012-04-25T22:59:23Z</wsu:Created> 
        </wsse:UsernameToken> 
        <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
         <wsu:Created>2012-04-25T22:59:23Z</wsu:Created> 
         <wsu:Expires>2012-04-25T22:60:23Z</wsu:Expires> 
        </wsu:Timestamp> 
       </wsse:Security> 
      </soap:Header> 

客戶機代碼:WSE 3.0創建的UsernameToken但用戶名和密碼的值是空

MessageServiceWse client = new MessageServiceWse(); 

UsernameToken usernameToken = new UsernameToken(token.Username, token.Password, PasswordOption.SendPlainText); 

client.RequestSoapContext.Security.Tokens.Add(usernameToken); 
client.RequestSoapContext.Security.Timestamp.TtlInSeconds = 60; 

client.SomeMethod(請求);

這美麗的肥皂安全頭,我設法噪音太大後創建安裝和VS 2010,但使用WSE 3.0我調用這個Web服務(我不控制)的地獄還在繼續,而wverything看起來很好,我無法理解這最後一個問題。

如果你注意到請求標題,你可以看到一切都很好,除了我用的用戶名和密碼不通過!

有人曾經遇到類似的情況嗎?

謝謝。

回答

3

不知道你是否仍然有這個問題,但是你可以嘗試這樣的事情嗎? 我不知道你爲什麼試圖從令牌對象獲取用戶名/密碼。這是客戶需要提供給服務的東西。

UsernameToken token = new UsernameToken("myusername", "mypwd", PasswordOption.SendPlainText); 

client.SetClientCredential(token); 
client.SetPolicy("ClientPolicy"); 
+0

請刪除代碼示例中的額外縮進並避免大行。 – 2012-05-02 02:36:37