我正在尝试连接到异地asmx-service。我有用于身份验证的asmx url和login-password。我已经添加了服务的服务引用和VS2010生成的WCF-client与配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="serviceSoap" />
</basicHttpBinding>
<customBinding>
<binding name="serviceSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://tourml.danko.ru:9191/Service.asmx"
binding="basicHttpBinding" bindingConfiguration="serviceSoap"
contract="DankoTourMLService.serviceSoap" name="serviceSoap" />
<endpoint address="http://tourml.danko.ru:9191/Service.asmx"
binding="customBinding" bindingConfiguration="serviceSoap12"
contract="DankoTourMLService.serviceSoap" name="serviceSoap12" />
</client>
我已经使用basicHttpBinding创建了客户端并设置了凭据。然后我尝试调用服务方法:
var service = new serviceSoapClient("serviceSoap");
service.ClientCredentials.UserName.UserName = username;
service.ClientCredentials.UserName.Password = password;
var items = service.GetItemList();但是这里抛出了System.ServiceModel.Security.MessageSecurityException:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.使用内部System.Net.WebException:
{"The remote server returned an error: (401) Unauthorized."}ClientCredentials设置有什么问题?我是否应该使用另一个绑定,而不是basicHttpBinding?
发布于 2014-03-13 20:38:20
http://msdn.microsoft.com/en-us/library/ms732391(v=vs.110).aspx根据上面的说明。当您需要指定凭据时,应设置端点的安全性。在您的配置中并非如此。
=>引用不能创建正确的配置有两种可能性(不太可能)。第二个=>,您必须在服务上而不是在传输上指定凭据。
var service = new serviceSoapClient("serviceSoap");
//service.ClientCredentials.UserName.UserName = username;
//service.ClientCredentials.UserName.Password = password;
service.setCredentials() (or something)
var itmes = service.getItems();您应该查找该服务的文档。
发布于 2018-06-19 00:19:44
我知道这是一个老帖子,但最近我遇到了同样的问题,也许我会帮助其他人我是如何解决它的。我有一个.net web应用程序,为支付系统使用SOAP服务,具有基本身份验证。解决方案是使用用户名前面带有'u‘的客户端凭据,并在web.config中指定绑定传输。
client.ClientCredentials.UserName.UserName = "uMyUsername";
client.ClientCredentials.UserName.Password = "MyPassword";在web.config中:
<bindings>
<basicHttpBinding>
<binding name="XYZ">
<security mode="Transport" >
<transport clientCredentialType="Basic"/>
</security>
</binding>
<binding name="XYZ" />
</basicHttpBinding>
</bindings>https://stackoverflow.com/questions/22374289
复制相似问题