Alex
Alex

Reputation: 160

Java CFX Webservice and Delphi 2010

I'm struggling around with some problems calling my Java Webservice. As long as I use primitive datatypes, such as Strings, Integers etc. everything works fine.

But when I try to use objects as parameters my java methods only receive null. So the mapping doesn't seem to work. I put up a simple example:

Java Interface for Webservice

@WebService(name="TestService", targetNamespace=CNAPBackOffice.NAMESPACE_SERVICES)
@SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL)
public interface TestService {
    @WebMethod(operationName="sendComplexType")
    @WebResult(name="okString")
    public String sendComplexType(TestData data);
}

Java Implementation

@WebService(endpointInterface = "lu.ciss.backoffice.cnap.services.TestService",
        portName = "TestEndpoint", serviceName = "TestService",
        targetNamespace = CNAPBackOffice.NAMESPACE_SERVICES)
public class TestServiceImpl implements TestService {

    @Override
    public String sendComplexType(TestData data) {
        return data.getTestString();
    }

}

TestData Class

public class TestData {
    String testString;
    ... + Setter/Getter for testString
}

I use the generated WSDL to import it to Delphi using the "Component->Import WSDL..." menu. Afterwards I call the Webservice like this:

procedure TFRM_Test.TestClick(Sender: TObject);
var
Service: TestService;
data: TestData;
result: String;
begin
  Service := GetTestService(true);
  data := TestData.Create;

  data.testString := 'Bla';

  result := Service.sendComplexType(data);

  ShowMessage(result);
end;

Like I said before, the Java side receives null which causes en exception in this case. So obviously the mapping between the two worlds isn't working correctly. I tried to change different options in the WSDL import menu, but nothing seems to work. I took a look at the SOAP request fired by Delphi:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS2="http://cnap.backoffice.ciss.lu/services">
        <NS1:sendComplexType xmlns:NS1="http://cnap.backoffice.ciss.lu/services">
            <arg0 href="#1"/>
        </NS1:sendComplexType>

        <NS2:testData id="1" xsi:type="NS2:testData">
            <testString xsi:type="xsd:string">Bla</testString>
        </NS2:testData>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I never saw before this strange notion of references. Could this cause the trouble? Or does someone else have another idea or even better: a solution :)

Thanks in advance.

P.S. Here is the generated WSDL:

<?xml version="1.0" ?><wsdl:definitions name="TestService" targetNamespace="http://cnap.backoffice.ciss.lu/services" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://cnap.backoffice.ciss.lu/services" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:types>
<xs:schema targetNamespace="http://cnap.backoffice.ciss.lu/services" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="testData">
    <xs:sequence>
      <xs:element minOccurs="0" name="testString" type="xs:string"></xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
  </wsdl:types>
  <wsdl:message name="sendComplexType">
    <wsdl:part name="arg0" type="tns:testData">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="sendComplexTypeResponse">
    <wsdl:part name="okString" type="xsd:string">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="TestService">
    <wsdl:operation name="sendComplexType">
      <wsdl:input message="tns:sendComplexType" name="sendComplexType">
    </wsdl:input>
      <wsdl:output message="tns:sendComplexTypeResponse" name="sendComplexTypeResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="TestServiceSoapBinding" type="tns:TestService">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
    <wsdl:operation name="sendComplexType">
      <soap:operation soapAction="" style="rpc"></soap:operation>
      <wsdl:input name="sendComplexType">
        <soap:body namespace="http://cnap.backoffice.ciss.lu/services" use="literal"></soap:body>
      </wsdl:input>
      <wsdl:output name="sendComplexTypeResponse">
        <soap:body namespace="http://cnap.backoffice.ciss.lu/services" use="literal"></soap:body>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="TestService">
    <wsdl:port binding="tns:TestServiceSoapBinding" name="TestEndpoint">
      <soap:address location="http://localhost:7777/CNAP_BackOffice/services/TestService"></soap:address>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Upvotes: 4

Views: 982

Answers (1)

Grzegorz Grzybek
Grzegorz Grzybek

Reputation: 6237

It's Delphi's fault.

Your JSR-181/JSR-224 annotated interface has explicit @SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL) and your generated WSDL states clearly that it's RPC/Literal WebService

  <wsdl:binding name="TestServiceSoapBinding" type="tns:TestService">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
    <wsdl:operation name="sendComplexType">
      <soap:operation soapAction="" style="rpc"></soap:operation>
      <wsdl:input name="sendComplexType">
        <soap:body namespace="http://cnap.backoffice.ciss.lu/services" use="literal"></soap:body>
      </wsdl:input>

Delphi however created Soap-Encoded SOAP 1.1 Envelope with MultiRef values and indicated it using SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/".

So you have to tweak some options in Delphi...

Maybe Delphi can't import RPC/Literal? Try switching to Document/Literal/Wrapped:

@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle = ParameterStyle.WRAPPED)

Upvotes: 5

Related Questions