2011-07-31 48 views
0

我試圖從ASP.NET MVC(3)應用程序中的web服務獲取結果。 web服務調用(見下文)完美地工作,我可以在Fiddler中看到我得到了適當的SOAP結果。SOAP web服務調用給出空結果

但是,對「client.requestAuthorisation」的調用會導致null。我錯過了什麼嗎?

public static string GetToken() 
    { 
     var token = ""; 
     var username = "user"; 
     var password = "pass"; 

     using (var client = new MvcApplication1.TheWebService.SingleSignOnSoapServerPortTypeClient()) 
     { 
      using (new System.ServiceModel.OperationContextScope(client.InnerChannel)) 
      { 
       var httpRequestProperty = new System.ServiceModel.Channels.HttpRequestMessageProperty(); 

       var authenticationString = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(string.Format("{0}:{1}", username, password))); 
       httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = string.Format("Basic {0}", authenticationString); 

       System.ServiceModel.OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] = httpRequestProperty; 

       token = client.requestAuthorisation("admin"); 
      } 
     } 

     return token; 
    } 

返回的SOAP消息如下:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.somedomain.ext" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
    <SOAP-ENV:Body> 
    <ns1:requestAuthorisationResponse> 
     <return xsi:type="xsd:string">6389a2dd8da662130e6ad1997267c67b043adc21</return> 
    </ns1:requestAuthorisationResponse> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

回答

0

您是否嘗試過重新生成客戶端代碼?