1

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

我正在使用带有 spring-ws 的 Java。并使用 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>
4

1 回答 1

1

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

<map-to xml="Response" ns-prefix="sch" />
于 2010-01-28T18:26:29.700 回答