Last post Jan 04, 2021 07:52 AM by yij sun
Dec 28, 2020 11:57 AM|dzeju555|LINK
I am trying to connect to the WebService with C# but I cannot attach certificate to the request. I succesfully authorized myself using SoapUI so I'm sure something is wrong with my code, not the WS.
First thing I done was generating proxy class with delivered WSDL file (using Add Service Reference option in Visual Studio). In my Web.config file I got code like this:
<binding name="myServiceSoapBinding" />
contract="xxxxxxxxxxxxx.myService" name="myServicePort" />
Then, according to that i wrote this code:
var basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Message);
basicHttpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
var endpoint = new EndpointAddress("http://xxxxxxxxxxxxxxx/myService");
myService.myServiceClient myServiceClient = new myService.myServiceClient(basicHttpBinding, endpoint);
var cert = new X509Certificate2(@"xxxxxx\key.p12", "password");
myServiceClient.ClientCredentials.ClientCertificate.Certificate = cert;
myService.NewOrderRequest = new myService.NewOrderRequest();
var result = myServiceClient.makeNewOrder(orderRequest);
Finally, I checked whole request and noticed, there is no wsse:Security tag. There is request I was about to send:
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--some params here-->
Hours of "making changes and testing" ago I was able to sucesfully send the request but WS replied that my certifcate is incorrect or missing. At this moment I'm just getting an exception: "The service certificate is not provided for target 'xxxxxxxx'. Specify
a service certificate in ClientCredentials". I stuck here and I have no more ideas. Of course I read a lot of similiar topic but nothing of them solve my problem. Can you help me?
Dec 29, 2020 06:09 AM|yij sun|LINK
"The service certificate is not provided for target 'xxxxxxxx'. Specify a service certificate in ClientCredentials".
Accroding to your description,as far as I think,your X509Certificate2 setting have errors.I suggest you need to check the configuration.
More details,you could refer to below article:
Dec 29, 2020 05:14 PM|dzeju555|LINK
Well, I tried load certificate from the store and directly from the file and I got the same result. The code in example is about using https (transport layer) + certificate to authorize. WebService I have to use doesn't suport SSL. Another thing is, WebService
needs basicHttpBinding. When I use wsHttpBindig it causes compatibility errors.
Dec 30, 2020 09:05 AM|yij sun|LINK
Do you have set the ClientCredentialType
property of the TransportSecurity ?
Just like this:
<transport clientCredentialType="Certificate" />
Jan 02, 2021 08:41 AM|dzeju555|LINK
Of course I tried, but I get an exception like this:
"The provided URI scheme 'http' is invalid; expected 'https'. Parameter name: via"
Jan 04, 2021 07:52 AM|yij sun|LINK
Accroding to your description,I think that the problem means you need to bind https. But it need to specify the SSL certificate.In your description,webservice don't support SSL，so I suggest you could do this:
Security mode= "Transport"
Security mode= "none"