在没有SOAP的情况下将JAX-WS RI迁移到Spring控制的服务?

时间:2013-08-14 15:13:45

标签: spring soap jax-ws

如果我使用不正确的术语,请原谅我,我对此有点新鲜。我使用Sun的JAX-WS RI“Provider”实现创建了一个Web服务。我们将此服务发送为纯XML,并以纯XML格式进行响应。我已经尝试将其移动到Spring中,因此可以通过Spring上下文访问服务,但现在它正在寻找一个我们没有使用的SOAP信封。我如何告诉它我没有使用SOAP?

我的web.xml如下所示:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <display-name>MyServiceImpl</display-name>
    <servlet-name>MyServiceImpl</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>MyServiceImpl</servlet-name>
    <url-pattern>/myServiceUrl</url-pattern>
</servlet-mapping>

这是我的applicationContext.xml:

<!-- this bean implements web service methods -->
<bean id="myService" class="com.acme.MyServiceImpl" />

<bean class="com.sun.xml.ws.transport.http.servlet.SpringBinding">
    <property name="url" value="/myServiceUrl" />
    <property name="service">
        <bean class="org.jvnet.jax_ws_commons.spring.SpringService">
            <property name="bean">
                <ref local="myService" />
            </property>
            <property name="impl" value="com.acme.MyServiceImpl" />
        </bean>
    </property>
</bean>

我的服务类看起来像这样:

@javax.xml.ws.WebServiceProvider
@javax.xml.ws.ServiceMode(value=javax.xml.ws.Service.Mode.MESSAGE)
public class MyServiceImpl implements Provider<Source> {

@Override
public Source invoke(Source source) {
... // unmarshal the source object using JAXB, do work, marshall a response back
}

我在发送服务时收到的错误消息是我的基本XML:

  

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"><faultcode>S:Client</faultcode><faultstring>Couldn't create SOAP message due to exception: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {}Request</faultstring></S:Fault></S:Body></S:Envelope>

如何摆脱SOAP?

1 个答案:

答案 0 :(得分:0)

找到它;需要在Web服务bean上指定bindingId(之前在sun-jaxws.xml中定义):

<property name="service">
    <bean class="org.jvnet.jax_ws_commons.spring.SpringService">
        <property name="bean">
            <ref local="myService" />
        </property>
        <property name="impl" value="com.acme.MyServiceImpl" />
        <property name="bindingID" value="http://www.w3.org/2004/08/wsdl/http" />
    </bean>
</property>