如何在没有wsdl url的情况下创建Axis客户端?

时间:2011-05-20 23:52:51

标签: java web-services axis

我想为使用本地wsdl的Web服务创建一个Axis客户端,而不知道wsdl的url。我已经尝试了本教程http://www.ibm.com/developerworks/webservices/library/ws-javaclient/index.html中的动态调用接口方法,但是我收到以下错误:

  

AxisFault faultCode:   {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException   faultSubcode:faultString:没有客户端   找到名为'null'的传输!   faultActor:faultNode:faultDetail:   {http://xml.apache.org/axis/}stackTrace:No   找到名为'null'的客户端传输!   在   org.apache.axis.client.AxisClient.invoke(AxisClient.java:170)

我的代码是:

        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);

谢谢

1 个答案:

答案 0 :(得分:2)

我和你的问题一样。 经过几个小时的挖掘,似乎我几乎解决了这个问题。 发生此异常是因为缺少设置目标端点地址 这是我的代码

        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);

targetEndpoint agument的值是port元素内地址元素的location属性的值。这是一个例子

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

您可以通过使用某些wsdlParser检索wsdl文档来获取此值(我使用Axis的WSDL4J)(请注意,在上面的代码示例中,我已经对targetEndpoint值进行了硬编码)

此外,我将OPERATION_STYLE_PROPERTY设置为rpc样式,将ENCODINGSTYLE_URI_PROPERTY设置为http://schemas.xmlsoap.org/soap/encoding/(这是默认值) Here是我发现解决此问题的文件

希望对你有所帮助!抱歉我的英语不好。