P
pramodr
Hi group,
I am quite new to webservices and in the process of learning and
evaluating spring-ws for my project. My question is that how to
invoke
an axis web service with spring-ws client ?
I have tried a spring-ws as follows to consume an axis ws.
Resource res = new
ClassPathResource("applicationContext.xml");
BeanFactory bf = new XmlBeanFactory(res);
WebServiceTemplate webServiceTemplate =
(WebServiceTemplate)bf.getBean("webServiceTemplate");
Source source = new StreamSource(new
StringReader(MESSAGE));
Result result = new StreamResult(System.out);
//this works.
webServiceTemplate.sendSourceAndReceiveToResult(
"http://localhost:8080/WS/
services/EmpService",
source, result);
//however this does not work.
Employee emp = new Employee();
emp.setEmpId("rrr");
emp.setEmpName("xxx");
Object o =
webServiceTemplate.marshalSendAndReceive(emp);
I need to send and receive POJOs. I think marshall/unmarshall is the
normal way. But since I use the above code, it throws me exception
org.springframework.ws.soap.client.SoapFaultClientException: No such
operation 'employee'.
So I think the request object (request payload) as they call it,
needs
to be passed instead of the pojo. But how do I do it?
Or is there a better way ?
Pasted below are the configurations. Any help in this regard is
highly
appreciated.
- Pramod
----------------
applicationContext.xml-----------------------------------------
<bean id="marshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
</bean>
<bean id="unMarshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
</bean>
<bean id="webServiceTemplate"
class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="defaultUri" value="http://localhost:
8080/WS/services/
EmpService"></property>
<property name="marshaller" ref="marshaller"></
property>
<property name="unmarshaller" ref="unMarshaller"></
property>
</bean>
------------------------------------------------------
-----------------EmpService.wsdl------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://test" xmlns:intf="http://test" xmlns:wsdl="http://
schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://
schemas.xmlsoap.org/
wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="http://test">
<element name="getEmp">
<complexType/>
</element>
<element name="getEmpResponse">
<complexType/>
</element>
<element name="getEmp2">
<complexType>
<sequence>
<element name="emp" type="impl:Employee"/>
</sequence>
</complexType>
</element>
<complexType name="Employee">
<sequence>
<element name="empId" nillable="true" type="xsd:string"/>
<element name="empName" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="getEmp2Response">
<complexType/>
</element>
<element name="getEmp3">
<complexType>
<sequence>
<element name="emp" type="impl:Employee"/>
</sequence>
</complexType>
</element>
<element name="getEmp3Response">
<complexType>
<sequence>
<element name="getEmp3Return" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="getEmp3Response">
<wsdlart element="impl:getEmp3Response" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmp2Response">
<wsdlart element="impl:getEmp2Response" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmpResponse">
<wsdlart element="impl:getEmpResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmpRequest">
<wsdlart element="impl:getEmp" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmp3Request">
<wsdlart element="impl:getEmp3" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmp2Request">
<wsdlart element="impl:getEmp2" name="parameters"/>
</wsdl:message>
<wsdlortType name="EmpService">
<wsdlperation name="getEmp">
<wsdl:input message="impl:getEmpRequest"
name="getEmpRequest"/
<wsdlutput message="impl:getEmpResponse"
name="getEmpResponse"/>
</wsdlperation>
<wsdlperation name="getEmp2">
<wsdl:input message="impl:getEmp2Request"
name="getEmp2Request"/>
<wsdlutput message="impl:getEmp2Response"
name="getEmp2Response"/>
</wsdlperation>
<wsdlperation name="getEmp3">
<wsdl:input message="impl:getEmp3Request"
name="getEmp3Request"/>
<wsdlutput message="impl:getEmp3Response"
name="getEmp3Response"/>
</wsdlperation>
</wsdlortType>
<wsdl:binding name="EmpServiceSoapBinding" type="impl:EmpService">
<wsdlsoap:binding style="document" transport="http://
schemas.xmlsoap.org/soap/http"/>
<wsdlperation name="getEmp">
<wsdlsoapperation soapAction=""/>
<wsdl:input name="getEmpRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdlutput name="getEmpResponse">
<wsdlsoap:body use="literal"/>
</wsdlutput>
</wsdlperation>
<wsdlperation name="getEmp2">
<wsdlsoapperation soapAction=""/>
<wsdl:input name="getEmp2Request">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdlutput name="getEmp2Response">
<wsdlsoap:body use="literal"/>
</wsdlutput>
</wsdlperation>
<wsdlperation name="getEmp3">
<wsdlsoapperation soapAction=""/>
<wsdl:input name="getEmp3Request">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdlutput name="getEmp3Response">
<wsdlsoap:body use="literal"/>
</wsdlutput>
</wsdlperation>
</wsdl:binding>
<wsdl:service name="EmpServiceService">
<wsdlort binding="impl:EmpServiceSoapBinding"
name="EmpService">
<wsdlsoap:address location="http://localhost:8080/WS/
services/
EmpService"/>
</wsdlort>
</wsdl:service>
</wsdl:definitions>
I am quite new to webservices and in the process of learning and
evaluating spring-ws for my project. My question is that how to
invoke
an axis web service with spring-ws client ?
I have tried a spring-ws as follows to consume an axis ws.
Resource res = new
ClassPathResource("applicationContext.xml");
BeanFactory bf = new XmlBeanFactory(res);
WebServiceTemplate webServiceTemplate =
(WebServiceTemplate)bf.getBean("webServiceTemplate");
Source source = new StreamSource(new
StringReader(MESSAGE));
Result result = new StreamResult(System.out);
//this works.
webServiceTemplate.sendSourceAndReceiveToResult(
"http://localhost:8080/WS/
services/EmpService",
source, result);
//however this does not work.
Employee emp = new Employee();
emp.setEmpId("rrr");
emp.setEmpName("xxx");
Object o =
webServiceTemplate.marshalSendAndReceive(emp);
I need to send and receive POJOs. I think marshall/unmarshall is the
normal way. But since I use the above code, it throws me exception
org.springframework.ws.soap.client.SoapFaultClientException: No such
operation 'employee'.
So I think the request object (request payload) as they call it,
needs
to be passed instead of the pojo. But how do I do it?
Or is there a better way ?
Pasted below are the configurations. Any help in this regard is
highly
appreciated.
- Pramod
----------------
applicationContext.xml-----------------------------------------
<bean id="marshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
</bean>
<bean id="unMarshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
</bean>
<bean id="webServiceTemplate"
class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="defaultUri" value="http://localhost:
8080/WS/services/
EmpService"></property>
<property name="marshaller" ref="marshaller"></
property>
<property name="unmarshaller" ref="unMarshaller"></
property>
</bean>
------------------------------------------------------
-----------------EmpService.wsdl------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://test" xmlns:intf="http://test" xmlns:wsdl="http://
schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://
schemas.xmlsoap.org/
wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="http://test">
<element name="getEmp">
<complexType/>
</element>
<element name="getEmpResponse">
<complexType/>
</element>
<element name="getEmp2">
<complexType>
<sequence>
<element name="emp" type="impl:Employee"/>
</sequence>
</complexType>
</element>
<complexType name="Employee">
<sequence>
<element name="empId" nillable="true" type="xsd:string"/>
<element name="empName" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="getEmp2Response">
<complexType/>
</element>
<element name="getEmp3">
<complexType>
<sequence>
<element name="emp" type="impl:Employee"/>
</sequence>
</complexType>
</element>
<element name="getEmp3Response">
<complexType>
<sequence>
<element name="getEmp3Return" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="getEmp3Response">
<wsdlart element="impl:getEmp3Response" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmp2Response">
<wsdlart element="impl:getEmp2Response" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmpResponse">
<wsdlart element="impl:getEmpResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmpRequest">
<wsdlart element="impl:getEmp" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmp3Request">
<wsdlart element="impl:getEmp3" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmp2Request">
<wsdlart element="impl:getEmp2" name="parameters"/>
</wsdl:message>
<wsdlortType name="EmpService">
<wsdlperation name="getEmp">
<wsdl:input message="impl:getEmpRequest"
name="getEmpRequest"/
<wsdlutput message="impl:getEmpResponse"
name="getEmpResponse"/>
</wsdlperation>
<wsdlperation name="getEmp2">
<wsdl:input message="impl:getEmp2Request"
name="getEmp2Request"/>
<wsdlutput message="impl:getEmp2Response"
name="getEmp2Response"/>
</wsdlperation>
<wsdlperation name="getEmp3">
<wsdl:input message="impl:getEmp3Request"
name="getEmp3Request"/>
<wsdlutput message="impl:getEmp3Response"
name="getEmp3Response"/>
</wsdlperation>
</wsdlortType>
<wsdl:binding name="EmpServiceSoapBinding" type="impl:EmpService">
<wsdlsoap:binding style="document" transport="http://
schemas.xmlsoap.org/soap/http"/>
<wsdlperation name="getEmp">
<wsdlsoapperation soapAction=""/>
<wsdl:input name="getEmpRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdlutput name="getEmpResponse">
<wsdlsoap:body use="literal"/>
</wsdlutput>
</wsdlperation>
<wsdlperation name="getEmp2">
<wsdlsoapperation soapAction=""/>
<wsdl:input name="getEmp2Request">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdlutput name="getEmp2Response">
<wsdlsoap:body use="literal"/>
</wsdlutput>
</wsdlperation>
<wsdlperation name="getEmp3">
<wsdlsoapperation soapAction=""/>
<wsdl:input name="getEmp3Request">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdlutput name="getEmp3Response">
<wsdlsoap:body use="literal"/>
</wsdlutput>
</wsdlperation>
</wsdl:binding>
<wsdl:service name="EmpServiceService">
<wsdlort binding="impl:EmpServiceSoapBinding"
name="EmpService">
<wsdlsoap:address location="http://localhost:8080/WS/
services/
EmpService"/>
</wsdlort>
</wsdl:service>
</wsdl:definitions>