none
Consuming java service in .NET and soapUI RRS feed

  • Question

  • I have been stuck on this problem with trying to consume a java web service for about a week now.  I keep thinking that I am getting close to a solution but no luck.
     
    Here is a brief layout of my requirements and problem.

    I need to consume a web service hosted in java from .NET.  This service is using UserNameToken for message level security.  I was given a soapUI project file (xml) to try and get data from the service.  This was successful but I cannot seem to do it with the proxy I generated from .NET.

    So I am now trying to use the same soapUI project file to generate .NET 2.0 Artifacts.  The problem is that when I do this I get a message back that reads, “Policy Falsified".  The service is behind a Layer 7 server (not very familiar with this).  Why is it that I can connect to the service in soapUI but I cannot generate a proxy through .NET 2.0 Artifacts?

    My hope is that once I can generate the proxy from soapUI then the I can use the proxy for my .NET client.

    Tuesday, October 18, 2011 11:03 PM

Answers

  • As a last sort, you can use a message inspector to modify the SOAP message before it's sent to the service. Override the BeforeSendRequest method.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by Yi-Lun Luo Tuesday, October 25, 2011 9:57 AM
    Friday, October 21, 2011 1:47 AM
  • That's interesting about the same time you sent this I started looking at this as an option.  It definitely worked.  Not only am I using the BeforeSendRequest but I am also using the AfterReceiveReply.  I will post a sample of the code I used along with a reference to the site that helped later.

    Thanks.


    • Edited by David _ M Saturday, October 22, 2011 12:54 AM added more text
    • Marked as answer by Yi-Lun Luo Tuesday, October 25, 2011 9:57 AM
    Saturday, October 22, 2011 12:53 AM

All replies

  • Hello, first of all, you must make sure the Java web service is interoperable. If must comply to WS-I Basic Profile. Otherwise it can only be consumed from a Java client. Second, you're working with .NET 2.0, where WCF doesn't exist. And you mentioned you're using SoapUI, a third party product, which has nothing to do with WCF. So your question is off topic on this forum. You should try to find a forum for SoapUI.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Thursday, October 20, 2011 2:10 AM
  • Thanks, I will confirm that the service is compliant with WS-I Basic Profile.

    Sorry for the confusion. I am working in .NET 4.0. The ".NET 2.0 Artifact" that I am referring to is an option inside the soapUI application. I am writing a WCF client in VS 2010 that needs to consume a java service.  I am simply using the soapUI tool to try and figure out why my proxy class is generating a soap envelope that does not match what is expected by the client.
    Thursday, October 20, 2011 3:12 AM
  • You can also try to compare the SOAP message generated by WCF with the one generated by SoapUI, to see what's the difference.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Thursday, October 20, 2011 3:47 AM
  • I have compared the two and I can see the difference.  I am not sure how to fix it though.  The problem seems to be the getApplicant node and the request node that is parent to the PersonRecord node.  I have mocked the client's service in .NET that I then add as service reference to consume it with my .NET client

    Here is the interface in .NET that generates the WRONG soap
    <ServiceContract(), XmlSerializerFormat(Style:=ServiceModel.OperationFormatStyle.Document, Use:=ServiceModel.OperationFormatUse.Literal)> _
    Public Interface IPortType
        <OperationContractAttribute(), _
        SoapDocumentMethod("http://www.NameOfClientsDomain/getApplicant", Use:=SoapBindingUse.Literal, ParameterStyle:=SoapParameterStyle.Wrapped)> _
        Function getApplicant(<XmlElement([Namespace]:="http://www.NameOfClientsDomain/request", isnullable:=True)> ByVal request As getApplicantRequest) As getApplicantResponse
    End Interface
     
    Here is the WRONG soap that is being generated when the above code is consumed by my .NET client
    <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">http://tempuri.org/IPortType/getApplicant</Action>
     </s:Header>
     <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <getApplicant xmlns="http://tempuri.org/">
       <request>
        <personRecord xmlns="http://www.NameOfClientsDomain/request">
         <ssn>123456789</ssn>
         <pr_id>987654321</pr_id>
         <compCd>G</compCd>
         <processDescription>ABCD</processDescription>
        </personRecord>
       </request>
      </getApplicant>
     </s:Body>
    </s:Envelope>
     
    Here is the CORRECT soap that the service is expecting.
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <personRecord xmlns="http://www.NameOfClientsDomain/request">
                <ssn>123456789</ssn>
                <pr_id>987654321</pr_id>
                <compCd>G</compCd>
                <processDescription>ABCD</processDescription>
            </personRecord>
    </s:Body>


    • Edited by David _ M Thursday, October 20, 2011 4:12 AM type-o
    Thursday, October 20, 2011 4:11 AM
  • Try to change style to Rpc to see if it makes any difference.

    Style:=ServiceModel.OperationFormatStyle.Rpc


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Thursday, October 20, 2011 4:50 AM
  • I gave that a try with no luck.
    Thursday, October 20, 2011 1:45 PM
  • As a last sort, you can use a message inspector to modify the SOAP message before it's sent to the service. Override the BeforeSendRequest method.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by Yi-Lun Luo Tuesday, October 25, 2011 9:57 AM
    Friday, October 21, 2011 1:47 AM
  • That's interesting about the same time you sent this I started looking at this as an option.  It definitely worked.  Not only am I using the BeforeSendRequest but I am also using the AfterReceiveReply.  I will post a sample of the code I used along with a reference to the site that helped later.

    Thanks.


    • Edited by David _ M Saturday, October 22, 2011 12:54 AM added more text
    • Marked as answer by Yi-Lun Luo Tuesday, October 25, 2011 9:57 AM
    Saturday, October 22, 2011 12:53 AM
  • Hi David_M,

    Any chance you could post or email me (rodneyg@affinityid.co.nz) the BeforeSendRequest & AfterReceiveReply code you used? I'm having the same issue & error response connecting .NET to a Java Layer7 web services. I have the wsdl files & may also need to pass through usertokens with the requests.

    Cheers

    Wednesday, December 7, 2011 7:43 PM
  • This post was very helpful, http://netindonesia.net/blogs/ferry/pages/WCF-Client-Message-Inspector.aspx.  If this doesn't help let me know and I can look at my solution again and provide more feedback.
    Thursday, December 8, 2011 2:39 AM
  • the problem is when you add the webreference in Visual Studio .net the proxy it generates having wrong namespace

    so just find for the namespace and remove from the autogenerated proxyclass and try 

    I faced the similar problem and worked fine once i removed the namespace in the proxyclass.

    regards

    Raj

    Wednesday, July 11, 2012 12:12 AM
  • Hi,

    I am facing the same issue, the link netindonesia.net/blogs/ferry/pages/WCF-Client-Message-Inspector.aspxdoes not open up. Can you please post the code for BeforeSendRequest and  AfterReceiveReply here so that can be helpful.

    Really appreciate your help.

    Wednesday, October 16, 2013 5:15 AM
  • Removing namespaces as well didn't work for me.. someone please help.
    Wednesday, October 16, 2013 5:16 AM
  • We had a similar problem implementing a WCF - Java connection recently.  I'm getting the Policy Falsified in production now which is a separate issue from what we were seeing in test environments.  I don't know if this has any bearing on your issue, but maybe it will help someone trying to connect .NET to Java. 

    We found that NET 4.5 did something to improve the top down WSDL deserialization.  We could generate service references (somewhat) fine in 4.0 but as soon as we called it, it would throw "Error deserializing XML".  Running the same code in 4.5 worked fine.  I was never able to get the SoapUI artifacts to connect successfully; though they did not complain when generate the proxy.  So, if you're not running on 4.5, I'd give that a try.  Policy Falsifieds on a layer 7 can hide several different underlying issues I've found.

    As for inspector code:

    public class MessageInspector : IClientMessageInspector

    {

            public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
            {
                this.MessageXML = reply.ToString(); //then do what you will... log, etc

            }

    }

    public class YourBehavior : IEndpointBehavior

    {

            public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
            {
                clientRuntime.MessageInspectors.Add(this.Inspector);
            }

    }

    Add the inspector to the client endpoint:

    ServiceClient client = new ServiceClient();

    MessageInspector inspector = new MessageInspector ();

    YourBehavior behavior = new YourBehavior(inspector); client.Endpoint.Behaviors.Add(behavior);

    • Edited by Roguewon Tuesday, February 4, 2014 8:50 PM Added EndpointBehavior code
    Tuesday, February 4, 2014 8:44 PM