none
Trouble setting restricted properties of httprequest header while sending SOAP requests to java web service using WSDL generated proxy class RRS feed

  • Question

  • I need to send SOAP requests to a Java Web service and get SOAP response back.
    I have a DotNet client that access the WS via a proxy class(Visual studio 2012 generated proxy from the WSDL, by adding web reference).
    Now the problem is, by default the content-type = text/xml; charset=utf-8 in the request header of the SOAP requests sent from my Client side, whereas the java based WS expects  content-type to be application/soap+xml;
    Since I should not edit the proxy class,I added one more partial class for the proxy and override the GetWebRequest(uri) method in the hope of controlling the request header inside this method. Please find the code I added:


    protected override System.Net.WebRequest GetWebRequest(Uri uri)
            {        
    HttpWebRequest request = base.GetWebRequest(uri) as HttpWebRequest;
    request.ContentType = "application/soap+xml;";
    return request;
            }

    Now when I debug my client, I can see the correct value being set in content type. However when I see the soap request sent from my client in fiddler, I see that content-type is back to default.
    Looks like, the value defaults to its original, after I programmatically set it.How to prevent this ?
    Any help is appreciated.

    I know I can have better control over the soap requests by sending HttpWebRequest to the WS directly without the use of proxy or WSDL, but that is not the solution I am looking for here.
    Reason being, we are the providers of the Java WS and our Client has developed a Dotnet client application along aforesaid lines and are requesting our help with the troubleshoot.

    Wednesday, January 11, 2017 1:02 PM

Answers

  • Hi pArunk,

    I suggest you follow Add Service Reference-> Enter address. As my understanding, Add Web Reference->Enter URL is used to asmx web service which did not support ws binding.

    You could refer the link below for calling java web service from .net client.

    #How To: Call a Java EE Web Service from a .Net Client

    https://blogs.msdn.microsoft.com/bursteg/2008/07/19/how-to-call-a-java-ee-web-service-from-a-net-client/

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by pArunK Friday, January 13, 2017 11:39 AM
    Thursday, January 12, 2017 8:15 AM

All replies

  • Hi pArunK,

    >> I have a DotNet client that access the WS via a proxy class(Visual studio 2012 generated proxy from the WSDL, by adding web reference).

    Could you share us more detailed steps about this? Do you follow Add Service Reference-> Enter address or Add Service Reference->Advanced->Add Web Reference->Enter URL? For WCF Service, you need to follow first option.

    >> Now the problem is, by default the content-type = text/xml; charset=utf-8 in the request header of the SOAP requests sent from my Client side, whereas the java based WS expects  content-type to be application/soap+xml;

    This is usually a mismatch in the client/server bindings, where the message version in the service uses SOAP 1.2(which expects application/soap+xml) and the version in the client uses SOAP 1.1(which sends text/xml). WSHttpBinding uses SOAP 1.2, BasicHttpBinding uses SOAP 1.1.

    Could you share us generated client app.config? I suggest you check whether it uses WSHttpBinding.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 12, 2017 5:29 AM
  • Hi Edward,
    Thanks for the response.
    As I mentioned in my problem description, the service side is JAVA webservice (hosted in TOMCAT).
    Hence I followed the second step mentioned in your reply i.e. Add Service Reference->Advanced->Add Web Reference->Enter WSDL

    As you pointed out, the WSDL definition does mention SOAP 1.2
            xmlns:soap12= "http://schemas.xmlsoap.org/wsdl/soap12/"
     
    However I cannot see how to set the binding information in the client side as the config generated contains nothing wrt bindings being used.
    Please refer below:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="WebClient.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
            </sectionGroup>
        </configSections>
        <startup>
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
        </startup>
        <system.serviceModel>
            <bindings />
            <client />
        </system.serviceModel>
        <applicationSettings>
            <WebClient.Properties.Settings>
                <setting name="WebClient_WebReference_XXXAPIWSService" serializeAs="String">
                    <value>http://ABACD:8080/xxx_apiWebService/api/xxx</value>
                </setting>
            </WebClient.Properties.Settings>
        </applicationSettings>
    </configuration>

    Can you suggest how to send SOAP 1.2 messages to a non-WCF service from DotNet client as I think ws-http binding is for Dotnet client to Dotnet service communication?

    Thanks in advance,

    pArunk

    Thursday, January 12, 2017 6:10 AM
  • Hi pArunk,

    I suggest you follow Add Service Reference-> Enter address. As my understanding, Add Web Reference->Enter URL is used to asmx web service which did not support ws binding.

    You could refer the link below for calling java web service from .net client.

    #How To: Call a Java EE Web Service from a .Net Client

    https://blogs.msdn.microsoft.com/bursteg/2008/07/19/how-to-call-a-java-ee-web-service-from-a-net-client/

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by pArunK Friday, January 13, 2017 11:39 AM
    Thursday, January 12, 2017 8:15 AM
  • Hi Edward,

    After following the steps mentioned in the link in your previous reply, my original issue got solved.Now I am able to send soap 1.2 messages with request header content-type = application/soap+xml.Thanks a lot.

    However I have a new issue at hand. My generated proxy class throws an exception while processing the soap 1.2 fault response from the service side. Apparently, the client is expecting the response fault message to contain xml:lang attribute value.

    Exception details:

    "Server returned an invalid SOAP Fault.  Please see InnerException for more details."

    Inner exception is: Required xml:lang attribute value is missing

    I am trying to figure out a way to handle this at client side itself, rather than modifying the service side schema reference. Kindly help if you have some ideas.

    Thanks,

    pArunk

    Friday, January 13, 2017 11:47 AM
  • Hi pArunk,

    For this new issue, I would suggest you post a new thread, and share us more information like how did you get this error?

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 13, 2017 12:05 PM
  • Sure Edward.Thanks.
    Monday, January 16, 2017 5:30 AM