Question

I'm having a problem with a WCF service trying to consume it from Java. The WCF is using basicHttpBinding and pretty simple definition:

public class MyService : IMyService
{
    public int MyMethod(MyObject obj)
    {

    }
}

The MyObject contains only String properties and looks like:

[DataContract]
public class MyObject
{
    [DataMember]
    public String Client { get; set; }

    ....
}

Now in Java, using Metro libaries, I'm creating the necessary classes like this:

wsimport -extension -keep -p com.myproject -Xnocompile http://localhost:3720/MyService.svc?wsdl

And finally consuming it like that:

MyService service = new MyService();
IMyService soap = service.getBasicHttpBindingIMyService();

ObjectFactory fact = new ObjectFactory();
MyObject obj = new MyObject();

obj.setClient(fact.createString("Someone"));

soap.MyMethod(obj);

Sniffing it with Fiddler it seems the data is properly sent to the service containing the "Someone" value for the Client property. Although when debugging the WCF service the Client property receives null value. Any ideas how to proceed?

Here is the SOAP message sent by the Java client:

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <MyMethod xmlns="http://tempuri.org/" xmlns:ns2="http://schemas.datacontract.org/2004/07/MyProject.MyService" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/">
            <MyObject>
                <ns3:string>Someone</ns3:string>
                <ns3:string>123-456-789</ns3:string>
                <ns3:string>Details</ns3:string>
                <ns3:string>12345</ns3:string>
                <ns3:string>Other</ns3:string>
                <ns3:string>user</ns3:string>
                <ns3:string>2012-01-01</ns3:string>
                <ns3:string>Registered</ns3:string>
            </MyObject>
        </MyMethod>
    </S:Body>
</S:Envelope>
Était-ce utile?

La solution

Finally I managed to resolve the issue. It seems the problem was within the Java code as an alternative .NET client was working properly. The parameter's properties was incorrectly set like this:

obj.setClient(fact.createString("Someone")); 

Instead the correct approach is

obj.setClient(fact.createMyObjectClient("Someone"));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top