Java – How to create Axis Client without wsdl’s url

axisjavaweb services

I want to create an Axis client for a web service with local wsdl, without knowing the wsdl's url. I've tried the Dynamic Invocation Interface method as in this tutorial http://www.ibm.com/developerworks/webservices/library/ws-javaclient/index.html but I get the following error:

AxisFault faultCode:
{http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode: faultString: No client
transport named 'null' found!
faultActor: faultNode: faultDetail:
{http://xml.apache.org/axis/}stackTrace:No
client transport named 'null' found!
at
org.apache.axis.client.AxisClient.invoke(AxisClient.java:170)

My code is:

        ServiceFactory factory = ServiceFactory.newInstance();
        Service service = factory.createService(new QName("http://j2ee.netbeans.org/wsdl/CompositionBpelModule/ComposedWebServiceService","ComposedWebServiceServiceService"));
        Call call = service.createCall();
        call.setPortTypeName(new QName("http://j2ee.netbeans.org/wsdl/CompositionBpelModule/ComposedWebServiceService","ComposedWebServiceServicePortType"));
        call.setProperty(Call.OPERATION_STYLE_PROPERTY, "wrapped");
        call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "");
        call.setReturnType(XMLType.XSD_STRING);
        call.setOperationName(new QName("http://j2ee.netbeans.org/wsdl/CompositionBpelModule/ComposedWebServiceService", "ComposedWebServiceServiceOperation"));
        call.addParameter("input1", XMLType.XSD_STRING, ParameterMode.IN);
        String[] params = {input};
        response = (String)call.invoke(params);

Thank you

Best Answer

I had the same problem as yours. After digging for hours, it seems like I've almost solved this problem. This exception occurs because of missing set target endpoint address Here is my code

        Call call = service.createCall();
        call.setPortTypeName(portQName);
        call.setOperationName(new QName(namespace, operation));
        call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "http://schemas.xmlsoap.org/soap/encoding/"); 
        call.setProperty(Call.OPERATION_STYLE_PROPERTY, "rpc");
        call.addParameter("in0", org.apache.axis.Constants.XSD_STRING ,ParameterMode.IN);
        call.addParameter("in1", org.apache.axis.Constants.XSD_STRING ,ParameterMode.IN);
        call.setReturnType(serviceQName);
        String targetEndpoint = "http://113.160.19.218:8312/axis/services/WeatherForecastTest1";
        call.setTargetEndpointAddress(targetEndpoint);
        String result = (String) call.invoke(params);
        out.println(result);

The value of targetEndpoint agument is the value of location attribute of address element inside port element. Here is an example

<service name="WeatherForecastTest1Service">
    <port binding="impl:WeatherForecastTest1SoapBinding" name="WeatherForecastTest1">
      <wsdlsoap:address location="http://113.160.19.218:8312/axis/services/WeatherForecastTest1"/>
   </port>
  </service>

You can get this value by retrieving wsdl document using some wsdlParser (I use Axis's WSDL4J) (Note that in the code example above, I have hardcoded the targetEndpoint value)

Moreover, I set OPERATION_STYLE_PROPERTY to rpc style and ENCODINGSTYLE_URI_PROPERTY to http://schemas.xmlsoap.org/soap/encoding/ (this is default value) Here is the document I found to solve this problem

Hope that help you! Sorry for my bad English.

Related Topic