设置 WS 响应架构时出现问题

发布于 2024-08-19 19:55:38 字数 2732 浏览 3 评论 0原文

我正在使用soapUI 来测试一些WebServices。

在soapUI中可用的MockService中,我得到这个默认响应

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www.someurl.com/schemas">
        <soapenv:Header/>
        <soapenv:Body>
             <sch:Response>
                 <sch:Something>?</sch:Something>
             </sch:Response>
        </soapenv:Body>
   </soapenv:Envelope>

当调用真正的Web服务时,我没有得到xmlns:sch =“http://www.someurl.com/schemas”并且响应中的元素不带有' sch' 前缀。这是我得到的:

       <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <soapenv:Header/>
            <soapenv:Body>
                 <Response>
                     <Something>something</Something>
                 </Response>
            </soapenv:Body>
       </soapenv:Envelope>

我正在使用 Java 和 spring-ws。并使用 Castor 将 xml 编组为 Java 对象。

如何在响应中包含架构?

编辑:添加配置详细信息。

myApplication-servlet.xml是这样的

<bean id="payloadMapping"
        class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
        <property name="endpointMap">
            <map>
                <entry
                    key="{http://www.someurl.com/schemas}MyRequest"
                    value-ref="myEndpoint"/>                
            </map>
        </property>
    </bean>

<bean id="myEndpoint"
        class="foo.bar.myEndpoint">
        <constructor-arg ref="messageSource" />
        <property name="marshaller" ref="marshaller" />
        <property name="unmarshaller" ref="marshaller" />
    </bean>

<bean id="myWsdlDefinition"
        class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
        <property name="schema">
            <bean class="org.springframework.xml.xsd.SimpleXsdSchema">
                <property name="xsd" value="/MyXsd.xsd" />
            </bean>
        </property>
        <property name="portTypeName" value="myPortTypeName" />
        <property name="locationUri" value="http://anotherUrl:8080/services" />
    </bean>

<bean id="marshaller" class="org.springframework.oxm.castor.CastorMarshaller">
        <property name="mappingLocation" value="classpath:mapping.xml" />
    </bean>

<bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="errors" />
    </bean>

I'm using soapUI to test some WebServices.

In MockService available in soapUI I get this default response

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www.someurl.com/schemas">
        <soapenv:Header/>
        <soapenv:Body>
             <sch:Response>
                 <sch:Something>?</sch:Something>
             </sch:Response>
        </soapenv:Body>
   </soapenv:Envelope>

When the real Webservice is called I don't get xmlns:sch="http://www.someurl.com/schemas" and the elements inside the response doesn't come with 'sch' prefix. Here is what I get:

       <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
            <soapenv:Header/>
            <soapenv:Body>
                 <Response>
                     <Something>something</Something>
                 </Response>
            </soapenv:Body>
       </soapenv:Envelope>

I'm using Java with spring-ws. And using Castor to marshall xml to Java Object.

How to include the schema in the response?

EDIT: Adding configuration details.

myApplication-servlet.xml is like this

<bean id="payloadMapping"
        class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
        <property name="endpointMap">
            <map>
                <entry
                    key="{http://www.someurl.com/schemas}MyRequest"
                    value-ref="myEndpoint"/>                
            </map>
        </property>
    </bean>

<bean id="myEndpoint"
        class="foo.bar.myEndpoint">
        <constructor-arg ref="messageSource" />
        <property name="marshaller" ref="marshaller" />
        <property name="unmarshaller" ref="marshaller" />
    </bean>

<bean id="myWsdlDefinition"
        class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
        <property name="schema">
            <bean class="org.springframework.xml.xsd.SimpleXsdSchema">
                <property name="xsd" value="/MyXsd.xsd" />
            </bean>
        </property>
        <property name="portTypeName" value="myPortTypeName" />
        <property name="locationUri" value="http://anotherUrl:8080/services" />
    </bean>

<bean id="marshaller" class="org.springframework.oxm.castor.CastorMarshaller">
        <property name="mappingLocation" value="classpath:mapping.xml" />
    </bean>

<bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="errors" />
    </bean>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若水般的淡然安静女子 2024-08-26 19:55:38

在映射文件中,我必须将 ns-prefix 放入 map-to 元素中。

<map-to xml="Response" ns-prefix="sch" />

In the mapping file I have to put ns-prefix in the map-to element.

<map-to xml="Response" ns-prefix="sch" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文