2011-05-20 77 views
1

我想用本地wsdl創建Web服務的Axis客戶端,但不知道wsdl的url。我已經試過了動態調用接口方法,在本教程中http://www.ibm.com/developerworks/webservices/library/ws-javaclient/index.html,但我得到了以下錯誤:如何創建沒有wsdl url的Axis客戶端?

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)

我的代碼是:

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

謝謝

回答

3

我有同樣的問題作爲你的。 挖了幾個小時後,似乎我幾乎解決了這個問題。發生 此異常,因爲缺少既定目標端點地址 這裏是我的代碼

 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的值是端口元素內的地址元素的位置屬性的值。下面是一個例子

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

你可以通過使用一些wsdlParser(我使用Axis的WSDL4J)檢索WSDL文檔此值(請注意,在上面的代碼示例中,我硬編碼了targetEndpoint值)

而且,我設置OPERATION_STYLE_PROPERTY到RPC風格和ENCODINGSTYLE_URI_PROPERTYhttp://schemas.xmlsoap.org/soap/encoding/(這是默認值) Here是我發現解決這個問題

希望能夠幫助您的文檔!對不起,我的英語不好。