Reputation: 18197
Can a .NET WCF Client program call an existing (vendor supplied) .asmx web service that uses WS-Security for logon?
In our case, the vendor has provided an .asmx web service with WS-Security. We are going to try to use SOAPUI and WCFTestHarness or WCFTestClient to access it first. Would rather use WCF if possible.
Thanks,
Neal Walters
Upvotes: 0
Views: 1112
Reputation: 33379
Yes, absolutely. WCF has great support for WS-Security. What kind of tokens are expected by the service for authentication?
Assuming it's just username/password, you would simply configure your binding to use TransportWithMessageCredential security where the client credential type is UserName (note: you must use the HTTPS to do this). First, define a binding like so:
<basicHttpBinding>
<binding name=“MyBinding”>
<security mode=“TransportWithMessageCredential”>
<transport clientCredentialType=“None” />
<message clientCredentialType=“UserName” />
</security>
</binding>
</basicHttpBinding>
Then configure your endpoint to use this binding:
<endpoint address="https://somewhere.com/TargetService.asmx" binding="basicHttpBinding" bindingConfiguration="MyBinding" />
Then at runtime, assuming you're using a generated proxy (i.e. ClientBase) you simply set the client credentials like so:
TargetServiceClient client = new TargetServiceClient();
client.Credentials.UserName.UserName = "myusername";
client.Credentials.UserName.Password = "mypassword";
Upvotes: 3