访问的时候,一直报下面这个错误。 警告: Interceptor for {http://gerun.com/}HelloWorldImplService#{http://gerun.com/}sayHello has thrown exception, unwinding now org.apache.cxf.interceptor.Fault: Unexpected wrapper element {testwebservice2:HelloWorld}sayHello found. Expected {http://gerun.com/}sayHello.
Service service = new Service(); System.out.println("bbbbbbbbb"); try{ Call call=(Call)service.createCall(); System.out.println("dddddddd"); call.setTargetEndpointAddress(new java.net.URL("http://localhost:8080/testwebservice2/HelloWorld")); System.out.println("cccccccccc"); call.setEncodingStyle(Constants.NS_PREFIX_SOAP_ENV); call.setOperationName(new QName("http://gerun.com/","sayHello")); //call.setReturnType(org.apache.axis.Constants.XSD_STRING); Object obj=call.invoke(new Object[]{}); System.out.println(obj.toString()); System.out.println(call.getTargetEndpointAddress()); return ; }catch(Exception e){
}
thanks for your responses.i did figure out the problem and fix it. I turns out I do have to deserialize the return by adding this code to the class that invokes the web service: SOAPMappingRegistry smr = new SOAPMappingRegistry(); StringDeserializer sd = new StringDeserializer (); smr.mapTypes (Constants.NS_URI_SOAP_ENC, new QName ("", "return"), null, null, sd); call.setSOAPMappingRegistry(smr); It has to do with the xsi:type, which is seen as "the most common interop problem." The Apache soap puts the xsi:type elements for all parameters in the request. But, the xsi:type is missing in the response, which includes result or return. When the xsi:type attribute of the result or return element is missing, the error message will say "SOA-ENV:Client;No deserialization found....." The solution is to add code to deserialize the return. The xsi:type problem does not show up when I run the application within WSAD 4.1.1. It only shows up when I run the client outside it. I hope this will help others to solve the deserialization problem on the client side. If it happens on the server side, you'll need to add the deserialization stuff in the deployment descriptor. Thanks for your help. You ranchers are a bunch of great guys. Thanks.
urn:AddressFetcher
urn:xml-soap-demo-calculator
urn是固定的,还是写成服务名字。
我的webservice的名字是HelloWorldImplService,类的名字叫HelloWorld。这里是不是写成
call.setTargetObjectURI("HelloWorldImplService:HelloWorld");
警告: Interceptor for {http://gerun.com/}HelloWorldImplService#{http://gerun.com/}sayHello has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unexpected wrapper element {testwebservice2:HelloWorld}sayHello found. Expected {http://gerun.com/}sayHello.
bean.xml文件是
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="HelloWorld" implementor="com.gerun.HelloWorldImpl" address="/HelloWorld" />
</beans>
两个类很简单就是一个sayHello()方法,里面打出一个字符串。访问这个地址http://localhost:8080/testwebservice2/HelloWorld?wsdl
得到下面的wsdl
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions name="HelloWorldImplService" targetNamespace="http://gerun.com/" xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://gerun.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <wsdl:types>
- <xs:schema elementFormDefault="unqualified" targetNamespace="http://gerun.com/" version="1.0" xmlns:tns="http://gerun.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sayHello" type="tns:sayHello" />
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse" />
- <xs:complexType name="sayHello">
<xs:sequence />
</xs:complexType>
- <xs:complexType name="sayHelloResponse">
- <xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
- <wsdl:message name="sayHelloResponse">
<wsdl:part element="tns:sayHelloResponse" name="parameters" />
</wsdl:message>
- <wsdl:message name="sayHello">
<wsdl:part element="tns:sayHello" name="parameters" />
</wsdl:message>
- <wsdl:portType name="HelloWorld">
- <wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHello" name="sayHello" />
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:HelloWorld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document" />
- <wsdl:input name="sayHello">
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output name="sayHelloResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="HelloWorldImplService">
- <wsdl:port binding="tns:HelloWorldImplServiceSoapBinding" name="HelloWorldImplPort">
<soap:address location="http://localhost:8080/testwebservice2/HelloWorld" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>访问http://localhost:8080/testwebservice2
得到
Available SOAP services:
HelloWorld
•sayHello
Endpoint address: http://localhost:8080/testwebservice2/HelloWorld
WSDL : {http://gerun.com/}HelloWorldImplService
Target namespace: http://gerun.com/
Unexpected wrapper element {testwebservice2:HelloWorld}sayHello found.
Expected {http://gerun.com/}sayHello.尝试改一下
targetNamespace="testwebservice2"
但用soap客户总不能成功。
System.out.println("bbbbbbbbb");
try{
Call call=(Call)service.createCall();
System.out.println("dddddddd");
call.setTargetEndpointAddress(new java.net.URL("http://localhost:8080/testwebservice2/HelloWorld"));
System.out.println("cccccccccc");
call.setEncodingStyle(Constants.NS_PREFIX_SOAP_ENV);
call.setOperationName(new QName("http://gerun.com/","sayHello"));
//call.setReturnType(org.apache.axis.Constants.XSD_STRING);
Object obj=call.invoke(new Object[]{});
System.out.println(obj.toString());
System.out.println(call.getTargetEndpointAddress());
return ;
}catch(Exception e){
}
I turns out I do have to deserialize the return by adding this code to the class that invokes the web service:
SOAPMappingRegistry smr = new SOAPMappingRegistry();
StringDeserializer sd = new StringDeserializer ();
smr.mapTypes (Constants.NS_URI_SOAP_ENC, new QName ("", "return"), null, null, sd);
call.setSOAPMappingRegistry(smr);
It has to do with the xsi:type, which is seen as "the most common interop problem." The Apache soap puts the xsi:type elements for all parameters in the request. But, the xsi:type is missing in the response, which includes result or return.
When the xsi:type attribute of the result or return element is missing, the error message will say "SOA-ENV:Client;No deserialization found....."
The solution is to add code to deserialize the return.
The xsi:type problem does not show up when I run the application within WSAD 4.1.1. It only shows up when I run the client outside it.
I hope this will help others to solve the deserialization problem on the client side. If it happens on the server side, you'll need to add the deserialization stuff in the deployment descriptor.
Thanks for your help. You ranchers are a bunch of great guys.
Thanks.