我使用spring ws jaxrpc来使用外部Web服务。
Web服务的配置如下。
<bean id="myWebService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
<property name="serviceInterface" value="jatis.avantrade.foundation.model.service.WeatherService"/>
<property name="wsdlDocumentUrl" value="http://www.w3schools.com/webservices/tempconvert.asmx?WSDL"/>
<property name="namespaceUri" value="http://tempuri.org/"/>
<property name="serviceName" value="TempConvert"/>
<property name="portName" value="TempConvertHttpPost"/>
<property name="endpointAddress" value="http://www.w3schools.com/webservices/tempconvert.asmx"/>
</bean>
<bean id="client" class="jatis.avantrade.foundation.model.service.WeatherServiceImpl">
<property name="service" ref="myWebService"/>
</bean>
然后,我将Web服务调用如下。
package jatis.avantrade.foundation.model.service;
import java.rmi.Remote;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.BindingType;
@WebService(serviceName = "TempConvert")
@SOAPBinding(style = Style.DOCUMENT)
@BindingType(value = "http://schemas.xmlsoap.org/wsdl/soap/http")
public interface WeatherService extends Remote {
@WebMethod(action = "http://tempuri.org/CelsiusToFahrenheit", operationName = "CelsiusToFahrenheit")
public String CelsiusToFahrenheit(String input);
}
但是,它会抛出异常。
Caused by: com.sun.xml.internal.ws.streaming.XMLStreamReaderException: unexpected XML tag. expected: {http://service.model.foundation.avantrade.jatis/}CelsiusToFahrenheitResponse but found: {http://tempuri.org/}CelsiusToFahrenheitResponse
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.verifyTag(XMLStreamReaderUtil.java:203)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.verifyTag(XMLStreamReaderUtil.java:211)
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:513)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:110)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
at $Proxy23.CelsiusToFahrenheit(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:520)
at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:494)
答案 0 :(得分:0)
尝试从bean定义中删除除serviceInterface
,endpointAddress
和serviceName
之外的所有属性。
这应该可以,并且足以使用您已生成wsdl2java
或类似接口的Web服务。