1
OK了JAX WS提供客戶端,所以我碰到一個例子就是關於如何創建使用JaxWsProxyFactoryBean一個客戶端的SEI-試圖創建使用JAXWSProxyFactoryBean
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(HelloWorld.class);
factory.setAddress("http://localhost:9000/helloWorld");
HelloWorld client = (HelloWorld) factory.create();
String reply = client.sayHi("HI");
System.out.println("Server said: " + reply);
System.exit(0); `
我試圖複製它的JAX WS Provider接口(因爲我找不到任何示例) -
public static void main(String args[]) throws Exception {
MessageFactory mf = MessageFactory.newInstance();
System.out.println("TEST");
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
System.out.println("TEST");
factory.setAddress("http://localhost:8123/SoapContext/SoapPort1");
System.out.println("TEST");
factory.setServiceClass(Provider.class);
System.out.println("TEST");
factory.setWsdlLocation("http://localhost:8123/SoapContext/SoapPort1?wsdl");
System.out.println("TEST");
Provider<SOAPMessage> client = (Provider<SOAPMessage>) factory.create();
//Below Never Prints
System.out.println("TEST");
SOAPFactory sf = SOAPFactory.newInstance();
SOAPMessage request = mf.createMessage();
SOAPBody reqBody = request.getSOAPBody();
Name bodyName = sf.createName("ClientInsertedmainbody");
reqBody.addBodyElement(bodyName);
SOAPElement reqContent = reqBody.addChildElement("client");
reqContent.setValue("JPFB\n");
SOAPElement reqContent2 = reqBody.addChildElement("client2");
reqContent2.setValue("clieennnt\n");
System.out.println(" Request from client " + request.getSOAPBody().getTextContent());
System.out.println("Invoking server through JPFB interface using SOAPMessage");
SOAPMessage soapResp = client.invoke(request);
System.out.println("Response from server: " + soapResp.getSOAPBody().getTextContent());
System.exit(0);
}
無論如何,它失敗。服務器工作正常。當我使用以另一種方式創建的客戶端時(使用Dispatch實例),它做出了響應。
錯誤消息 -
May 19, 2015 6:44:55 PM org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://ws.xml.javax/}ProviderService from WSDL: http://localhost:8123/SoapContext/SoapPort1?wsdl
Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service {http://ws.xml.javax/}ProviderService.
at org.apache.cxf.wsdl11.WSDLServiceFactory.create(WSDLServiceFactory.java:158)
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:405)
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:525)
at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:261)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:199)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91)
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157)
at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142)
at main.JSFBClient.main(JSFBClient.java:40)
權的問題:什麼是錯的,如何解決?我感到嘮叨的感覺,我寫的代碼可能完全關閉,但嘿在那種情況下,我該怎麼做?
編輯:這裏是WSDL
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost:8123/SoapContext/SoapPort1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://server/" name="Provider1" targetNamespace="http://localhost:8123/SoapContext/SoapPort1">
<wsdl:import location="http://localhost:8123/SoapContext/SoapPort1?wsdl=Provider1.wsdl" namespace="http://server/">
</wsdl:import>
<wsdl:binding name="Provider1SoapBinding" type="ns1:Provider1">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="invoke">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="invoke">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="invokeResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Provider1">
<wsdl:port binding="tns:Provider1SoapBinding" name="Provider1Port">
<soap:address location="http://localhost:8123/SoapContext/SoapPort1"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
是的URL訪問?顯示WSDL。 –
@LeosLiterak檢查我的編輯。並感謝編輯我的代碼:P ...格式化是一場噩夢 –
我想知道CXF在哪裏得到了「{http://ws.xml.javax/} ProviderService」。看看http:// localhost:8123/SoapContext/SoapPort1?wsdl = Provider1.wsdl。我會嘗試SoapUI - 它可以生成並運行http:// localhost:8123/SoapContext/SoapPort1?wsdl的一些測試嗎? –