Hi,
Basically the WSDL can contain more than one service and multiple ports inside
one service.
Therefore, in case of specifying WSDL location, Dispatch should know what
exactly will be called.
Any chance to specify service name and port name can be specified as
configuration parameters?
If you do not use WSDL related features (WS-Policies, schema validation, etc),
consider to create the service without WSDL location. In this case service name
and port name doesn't really matter, you can use any:
QName serviceName = new QName("http://org.apache.cxf",
"stockQuoteReporter");
Service s = Service.create(serviceName);
QName portName = new QName("http://org.apache.cxf",
"stockQuoteReporterPort");
Dispatch<DOMSource> dispatch = s.createDispatch(portName,
DOMSource.class,
Service.Mode.PAYLOAD);
...
Regards,
Andrei.
> -----Original Message-----
> From: Pasadi Munasinghe [mailto:[email protected]]
> Sent: Mittwoch, 18. Februar 2015 01:33
> To: [email protected]
> Subject: Creating a Dispatch Client Using by Only Using the WSDL
>
> Hi,
> Currently I'm implementing a Client in CXF using JAX-WS Dispatch API. This
> client should be as dynamic as possible. But in the dispatch api, while
> creating a
> service and a dispatch, you need to give Qnames for service name and port
> name.
> The only input that I have is the wsdl file hosted at the remote service.
> At the moment, I'm parsing the wsdl using DOM parser to get the necessary
> values as servicename, portname and namespace. Is there any other way than
> this to receive these values than parsing the wsdl ?
> Thanx...!!
>
> Following is the code that I used.
>
> SpringBusFactory bf = new SpringBusFactory();
> URL busFile = Client.class.getResource("/ client.xml");
> Bus bus = bf.createBus(busFile.toString());
> BusFactory.setDefaultBus(bus);
>
>
> URL wsdl = new URL("
> http://localhost:9000/SoapContext/GreeterPort?wsdl");
> HttpURLConnection connection =(HttpURLConnection)
> wsdl.openConnection();
> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> dbf.setNamespaceAware(true);
> DocumentBuilder db = dbf.newDocumentBuilder();
> Document document = db.parse(new
> InputSource(connection.getInputStream()));
>
> String service=
> document.getElementsByTagName("service").item(0).getAttributes().getName
> dItem("name").getNodeValue();
> String
> port=document.getElementsByTagName("port").item(0).getAttributes().getNa
> medItem("name").getNodeValue();
> String
> binding=document.getElementsByTagName("port").item(0).getAttributes().get
> NamedItem("binding").getNodeValue();
> String[] splitTag=binding.split(":");
> String
> nameSpace=document.getFirstChild().lookupNamespaceURI(splitTag[0]);
>
>
> QName serviceName = new QName(nameSpace, service);
> QName portName = new QName(nameSpace,port);
>
> Service s =Service.create(wsdl,serviceName);
> Dispatch<SOAPMessage> dispatch = s.createDispatch(portName,
> SOAPMessage.class, Service.Mode.MESSAGE);
> InputStream is =
> Client.class.getResourceAsStream("/greeterMessage.xml");
> if (is == null) {
> System.err.println("Failed to create input stream from file
> ");
> System.exit(-1);
> }
> SOAPMessage soapReq1 =
> MessageFactory.newInstance().createMessage(null, is);
> dispatch.invoke(soapReq1);
> Thread.sleep(30 * 1000);
> bus.shutdown(true);
>
>
> --
> Pasadi Munasinghe
> Software Engineer Intern
> WSO2, Inc
> Mobile: +9471 377 5515