0
我試圖連接到異地asmx服務。我有ASMX網址和登錄密碼進行身份驗證。我已經添加服務引用到服務和VS 2010生成的WCF的客戶端配置:使用登錄密碼認證的WCF客戶端
<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?
嘗試像這樣創建你的服務=> var service = new serviceSoapClient();你可能指定了錯誤的綁定。 – woutervs
我已經嘗試了他們兩個,但同樣的錯誤發生 – WabiSabi