I'm trying to connect to off-site asmx-service. I have asmx url and login-password for authentication. I've add Service Reference to the service and VS 2010 generated WCF-client with config:
<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>
I've created client with basicHttpBinding and set credentials. Then I'm trying to call service method:
var service = new serviceSoapClient("serviceSoap");
service.ClientCredentials.UserName.UserName = username;
service.ClientCredentials.UserName.Password = password;
var items = service.GetItemList();
But here System.ServiceModel.Security.MessageSecurityException is thrown:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.
with inner System.Net.WebException:
{"The remote server returned an error: (401) Unauthorized."}
What's wrong with ClientCredentials setting? Should I use another binding, not basicHttpBinding?