Search code examples
javac#web-serviceswsdl

calling java web service "REST" that require auth with username & password and certificate from .Net C#


Ok here is my story, i have java web service from third party i have to connect to this service using C# this service require the following

  • Authentication using Username & Password.
  • Certificate send from the client "keystore.jks" (Java Keystore file) with password.

My problem is the vendor of this service is not providing the WSDL link for the service and the certificate file is java keystore I'm hanging on this for 2 days and search for this on the web with no luck

Hence : I used SOAPUI software to call this service and its working well

What i want is, Is it possible to consume this service without requesting WSDL from the vendor? if yes how ?

Any help well be appreciated. Thanks in advance.

EDIT: service url like https://10.111.10.12/ropnrs/Person?crn=1234567 And it's not accessible throw web browser return 403 forbidden


Solution

  • You can consume a webservice without a WSDL by sending a POST request with the WebClient, and filling the body of the request with the SOAP XML message.

    You might need to add additional HTTP headers. First do a request with SOAP UI and look at the request with fiddler. Then send the request with WebClient. The code should be similar to this:

    using (var client = new WebClient())
    {
        // this is the string containing the soap message
        var data = File.ReadAllText("request.xml");
        // HTTP header. set it to the identical working example you monitor with fiddler from SOAP UI
        client.Headers.Add("Content-Type", "text/xml;charset=utf-8");
        // HTTP header. set it to the identical working example you monitor with fiddler from SOAP UI 
        client.Headers.Add("SOAPAction", "\"http://tempuri.org/ITestWcfService/TestMethod\"");
        // add/modify additional HTTP headers to make the request identical with what you get when calling from SOAP UI on a successful call 
        try
        {
            var response = client.UploadString("http://localhost:8080/TestWcfService", data);
        }
        catch (Exception e)
        {
            // handle exception                        
        }
    }
    

    I'm not sure about the certificate, but maybe you can set it to the web client too somehow. Unfortunately, I don't know much about client certificates. But if you can explain in comments I might be able to help you. If you manage to make it work using this solution, please also post here your additional work to handle the certificate problem.

    WebClient is the class from System.Net in System.dll assembly.