Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

Cannot add certificate to the SOAP request

$
0
0

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:

<system.serviceModel><bindings><basicHttpBinding><binding name="myServiceSoapBinding" /></basicHttpBinding></bindings><client><endpoint address="http://xxxxxxxxxxxxxxx/myService"
    binding="basicHttpBinding" bindingConfiguration="myServiceSoapBinding"
    contract="xxxxxxxxxxxxx.myService" name="myServicePort" /></client></system.serviceModel>

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;
myServiceClient.Endpoint.Behaviors.Add(new DebugMessageBehavior());
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:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" /></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><newOrderRequest xmlns="http://xxxxxxxxxxxxx/"><requestHeader xmlns=""><!--some params here--></requestHeader></newOrderRequest></s:Body></s:Envelope>

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?


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>