【发布时间】:2016-09-06 17:19:34
【问题描述】:
我想使用此代码使用 Web 服务:
WebService.GenRelClient client = new WebService.GenRelClient();
client.ClientCredentials.UserName.UserName = @"UserName";
client.ClientCredentials.UserName.Password = @"Password";
var response = client.returnString("test");
我的配置是这样的:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="GenRelClientPortBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint
address="http://ws.domain.com/GenRel/GenRel"
binding="basicHttpBinding"
bindingConfiguration="GenRelClientPortBinding"
contract="WebService.GenRelClientPort"
name="GenRelClientPort" />
</client>
</system.serviceModel>
</configuration>
请求被发送到 Web 服务,响应被发送回来,其中包含关于它需要基本身份验证的错误消息,因为发送的请求可能没有凭据,所以我不知道在哪里错误。
感谢您的帮助
【问题讨论】:
-
我不同意这个问题与标题为“如何将用户凭据传递给 Web 服务”的问题重复。 Bushwacka 面临的问题是服务器配置为使用抢先式身份验证。一个非常特殊的情况,它要求客户端在 SOAP 标头中发送身份验证信息。前面提到的问题都没有解决这些问题。
标签: c# web-services wcf basic-authentication