As the title says, I need to get some Java 1.5 code to call a WCF web service. I've downloaded and used Metro to generate Java proxy classes, but they aren't generating what I expect, and I believe this is because of the WSDL that the WCF service generates.
My WCF classes look like this (full code omitted for brevity):
public class TestService : IService
{
public TestResponse DoTest(TestRequest request)
{
TestResponse response = new TestResponse();
// actual testing code...
response.Result = ResponseResult.Success;
return response;
}
}
public class TestResponse : ResponseMessage
{
public bool TestSucceeded { get; set; }
}
public class ResponseMessage
{
public ResponseResult Result { get; set; }
public string ResponseDesc { get; set; }
public Guid ErrorIdentifier { get; set; }
}
public enum ResponseResult
{
Success,
Error,
Empty,
}
and the resulting WSDL (when I browse to http://localhost/TestService?wsdl=wsdl0) looks like this:
<xsd:element name="TestResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" name="TestSucceeded" type="xsd:boolean" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ErrorIdentifier" type="q1:guid" xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/" />
<xsd:simpleType name="ResponseResult">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Error" />
<xsd:enumeration value="Success" />
<xsd:enumeration value="EmptyResult" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="ResponseResult" nillable="true" type="tns:ResponseResult" />
<xsd:element name="Result" type="tns:ResponseResult" />
<xsd:element name="ResultDesc" nillable="true" type="xsd:string" />
...
<xs:element name="guid" nillable="true" type="tns:guid" />
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
</xs:restriction>
</xs:simpleType>
Immediately I see an issue with this WSDL: TestResponse does not contain the properties inherited from ResponseMessage. Since this service has always worked in Visual Studio I've never questioned this before, but maybe that could be causing my problem?
Anyhow, when I run Metro's wsimport.bat on the service the following error message is generated:
[WARNING] src-resolve.4.2: Error resolving component 'q1:guid'
and the outputted Java version of TestResponse lacks any of the properties from ResponseMessage.
I hacked the WSDL a bit and changed ErrorIdentifier to be typed as xsd:string, which makes the message about resolving the GUID type go away, but I still don't get any of ResponseMessage's properties.
Finally, I altered the WSDL to include the 3 properties from ResponseMessage in TestResponse, and of course the end result is that the generated .java file contains them. However, when I actually call the WCF service from Java, those 3 properties are always null.
Any advice, apart from writing the proxy classes myself?