SOAP webservice调用给出null结果

时间:2011-07-31 18:43:49

标签: asp.net web-services soap service-reference

我试图从ASP.NET MVC(3)应用程序中的Web服务获取结果。 webservice调用(见下文)工作得很好,我可以在Fiddler中看到我得到了一个合适的SOAP结果。

但是,对“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>

1 个答案:

答案 0 :(得分:0)

您是否尝试过重新生成客户端代码?