1

我有一个带有服务参考的 Windows Phone 8 项目(在 C# 中)。是否可以将 http 客户端凭据类型设置为 NTLM?我需要提供域名、用户名和密码。

我正在使用带有 TransportCredentialOnly 选项的 BasicHttpBinding。这是在 *.ClientConfig 文件中完成的:

<configuration>
 <system.serviceModel>
  <bindings>
    <basicHttpBinding>
     <binding name="WSSoap" maxBufferSize="XXX" maxReceivedMessageSize="XXX">
       <security mode="TransportCredentialOnly" />
      </binding>
        </basicHttpBinding>
      </bindings>
      <client>
        <endpoint address="http://<address>" binding="basicHttpBinding"
            bindingConfiguration="WSSoap" contract="WorkListService.WSSoap"
            name="WSSoap" />
      </client>
  </system.serviceModel>
 </configuration>

但我还需要将 ClientCredentialType 设置为 NTLM 并提供 ServiceCredentials:域、用户名和密码。

这可以通过实现生成的服务类的部分 ConfigureEndpoint 方法在 Windows 应用商店应用程序中轻松完成。但我不知道如何在 Windows Phone 8 中做到这一点。

我注意到只有用户名和密码可用(基本身份验证):

*.ClientCredentials.UserName.UserName
*.ClientCredentials.UserName.Password
4

1 回答 1

0

我没有任何手机开发经验。我在 C# 服务级别做什么。

Uri uri = new Uri("http://whatever.com");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

NetworkCredential networkCredentials = new NetworkCredential();
networkCredentials.Domain = "Domain";
networkCredentials.UserName = "User";
networkCredentials.Password = "Pass";

CredentialCache cc = new CredentialCache();
cc.Add(uri, "Basic", networkCredentials); //NTLM can be used here, but Basic usually works.

request.Credentials = cc;
request.Method = WebRequestMethods.Http.Get;

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    ...
}
于 2013-06-18T13:26:06.543 回答