Reputation: 51
I'm trying to call a .net wcf service from JAVA code (WSDL4J). But WSDL4J failed to parse the response of .net service. I have used basichttpbinding protocol.
Actual Response from Service -----
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<TestResponse xmlns="http://tempuri.org/">
<TestResult>hi Test</TestResult>
</TestResponse>
</s:Body>
</s:Envelope>
I have done some more analysis on this and found that WSDL4j works fine if response is like this -
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<t:TestResponse xmlnst:t="http://tempuri.org/">
<TestResult>hi Test</TestResult>
</TestResponse>
</s:Body>
</s:Envelope>
I mean WSDL4J parses .net response correctly if xml namespase are are specified this way.
So the question is - how can we modify .net response to achive the new xml response or what changes we can do, so that JAVA part can parse .net service response??
Upvotes: 0
Views: 412
Reputation: 12680
The main issue is that WCDL4J seems to expect the TestResult element to be in some default or empty XML namespace and not in the "http://tempuri.org" namespace. The soap produced by the WCF service correctly creates a TestResponse element to have all its child elements be in the same XML namespace and resets the default XML namespace to be "http://tempuri.org".
The WSDL4J parser seems to expect that namespace to only apply to the TestResponse element but not TestResult element. That seems like a bug to me but there's probably not anything you can do about it.
If you're still reading, there are a couple of ways to attempt to fix this. The quick & easy way is to force WCF to use the same XML namespace for all the soap body elements it creates. To do this follow the advice in this MSDN post for XML namespaces for both the ServiceContract and DataMember attributes for your service. This may make the WSDL4J parser behave differently when it uses your namespace instead of whatever default it uses but there is no guarantee this will work. For example:
[ServiceContract(Namespace = "http://YourCo/2011/05/18/YourDomain")]
public interface ICalculator
{
[OperationContract]
double Add(double n1, double n2);
[OperationContract]
double Subtract(double n1, double n2);
[OperationContract]
double Multiply(double n1, double n2);
[OperationContract]
double Divide(double n1, double n2);
}
[DataContract(Namespace = "http://YourCo/2011/05/18/YourDomain")]
public class Customer
{
[DataMember]
public string Name {get; set;}
[DataMember]
public int ID {get; set;}
}
If that does not work, then you'll have to take the approach shown in the question & answer which is much more involved but it allow you to craft the soap message precisely.
Upvotes: 1