Tag Archives: CXF Call webservice Client Error

[Solved] CXF Call webservice Client Error: 2 counts of InaccessibleWSDLException

Background
The webservice service is used for interface communication in the project. In the specific application, the caller does not access the service directly, but forwards the request through a proxy to achieve access.

Problem
The client code generated by using apache axis1.4 tool to invoke the service can be accessed normally; the client code generated by using apache cxf tool reports an error: 2 counts of InaccessibleWSDLException.

Reason
The client code of axis is written with service name, port type and other information fixed in the generated code, while the client code of cxf is parsed by GET to get the wsdl file and bind service name and port name and other information before calling the interface.

image

In the project, because the proxy redirection interface address is used, the wsdl file cannot be directly obtained through GET for parsing, so an error is reported.

Solution:

  • a. Store the wsdl file locally, read the local wsdl file in the client, and fill in the address of the actual interface in the soap address label in the wsdl file
<service name="xxxService">
   <port binding="xxxSOAPBinding" name="xxxSOAPPort">
      <soap:address location="http://yourActualAddress/xxxService"/>
   </port>
</service>
  • b. Change the calling code to skip the step of getting the wsdl.
xxxService ss = new xxxService(null, SERVICE_NAME);
XXXServicePortType port = ss.getPort(xxxServicePortType.class);

BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
  .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
    "http://www.example.com/real_endpoint_url_goes_here");
Response res = port.yourMethods(...);