2

我正在使用 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)
4

1 回答 1

0

尝试从 bean 定义中删除除 、 和 之外的所有serviceInterface属性endpointAddressserviceName

这应该可以工作,并且足以使用您生成的接口wsdl2java或类似接口的 Web 服务。

于 2012-06-14T02:04:57.527 回答