在Windows Phone 8中使用Windows身份验证调用Web服务

时间:2014-10-11 16:16:40

标签: c# web-services windows-phone-8 windows-authentication

我正在尝试使用Windows Phone 8中的Windows身份验证调用Web服务(Exchange EWS)。 添加服务引用并在手动配置ServiceReferences.ClientConfig后使用:

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IEWS" maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647">
          <security mode="Transport">
          </security>            
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://servername/EWS/Exchange.asmx"
          binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IEWS"
          contract="ServiceReference1.ExchangeServicePortType"
          name="BasicHttpBinding_IEWS" />
    </client>
  </system.serviceModel>
</configuration>

用以下方式调用它:

    ServiceReference1.ExchangeServicePortTypeClient client = new ServiceReference1.ExchangeServicePortTypeClient();            
    client.ClientCredentials.UserName.UserName = @"username";
    client.ClientCredentials.UserName.Password = @"password";            
    client.GetRoomListsCompleted += client_GetRoomListsCompleted;
    client.GetRoomListsAsync(new ServiceReference1.GetRoomListsType());

我得到了

The remote server returned an unexpected response: (401) Unauthorized. 
In Silverlight, a 404 response code may be reported even when the service sends a different error code.

错误。 我尝试了各种配置更改。 最明显的一个

<transport clientCredentialType="Windows" />

导致

Unrecognized element 'security' in service reference configuration. Note that only a subset of the Windows Communication Foundation configuration functionality is available in Silverlight.

现在我开始相信(我无法提出谷歌结果来确认),不可能在带有网络服务的Windows Phone 8中使用Windows身份验证。

我到目前为止找到的唯一解决方案是使用和构建/解析我自己的肥皂内容

    WebClient c = new WebClient();
    c.BaseAddress = "https://servername/EWS/Exchange.asmx";
    c.Credentials = new NetworkCredential("username", "password", "domain");

任何想法? 对此有何帮助? 任何验证我的假设的链接?

有没有使用代理类在c#中处理soap请求的源代码示例?

0 个答案:

没有答案