Reputation: 113
Ok, so I came across an example on how to create a client using JaxWsProxyFactoryBean for an SEI-
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); `
I tried to duplicate it for a JAX WS Provider Interface(since I couldn't find any examples)-
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);
}
Anyway, it fails. The server is working fine. It responded when I used a client created in another way (Using a Dispatch instance).
The error messages -
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)
Right the question: What's wrong and how do I fix it? I get the nagging feeling that the code I wrote might be completely off, but hey in that case, how would I do it?
EDIT : Here is the 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>
Upvotes: 2
Views: 12019
Reputation: 11
Try to remove this line of code:
factory.setWsdlLocation("http://localhost:8123/SoapContext/SoapPort1");
Upvotes: 1