I'm trying to set up a call to a secured HTTPS endpoint and establish SOAP based communication with the code below. I created a web service reference using Visual Studio and the service's WSDL.
//NetHttpsBinding binding = new NetHttpsBinding();
NetHttpsBinding binding = new NetHttpsBinding();
string url = "https://" + ...;
EndpointAddress address = new EndpointAddress(url);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//CustomClient client = new CustomClient();
CustomClient client = new CustomClient(binding, address);
client.ClientCredentials.UserName.UserName = "monkey";
client.ClientCredentials.UserName.Password = "donkey";
FindUsersByUserIdRequest request = new FindUsersByUserIdRequest
{
applicationId = "kaweb",
searchMatchMode = "EXACT",
soughtUserId = "197002150485"
};
FindUsersByUserIdResponse response = client.FindUsersByUserId(request);
User[] result = response.users;
The computer doesn't like it and tells me something like this, with 401 specified. (Something because it's in a weird language we don't understand. And yes, there's a special corner of hell devoted for people who won't use English in coding because it's oh, gosh, so much easier to understand.)
System.ServiceModel.Security.MessageSecurityException:
Http request is not approved according to client schema Anonymous. Autentization header from server was Basic realm="CT".
When I check the available bindings, I see that I'm supposed to use NetHttpsBinding
(because we work against HTTPS as stated by the URL). The authentication method is suggested here and I tried to roughly follow this approach.
The endpoint as such works and produces correct values, which I verify using SoapUI and basic authentication with the same set of credentials. Also, other people are claimed to be able to fetch the info, according to the general hintification (although I suspect then have Java based clients).
I've tried googling how to specify the authentication schema but failed to find relevant information (or was too ignorant to recognize when it was there). According to this suggestion I should manipulate the headers in the request. I don't seem to have that field accessible in FindUsersByUserIdRequest
object though (and overriding it seems as a bad idea since it's auto-generated and I can't control it.
How do I do that and/or how can I troubleshoot it further?