首页 > 解决方案 > 以 RESTful 方式调用轴 2 Web 服务时出现名称空间不匹配错误

问题描述

我有一个axis2 Web 服务应用程序。它是使用轴 2 1.7.8 构建的。

以下是 Web 服务调用“关闭”的 wsdl

<wsdl:definitions targetNamespace="vish_testweb_close" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="vish_testweb_close" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl">
   <wsdl:documentation>vish_testweb_close</wsdl:documentation>
   <wsdl:types>
      <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="vish_testweb_close">
         <xs:element name="close">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" name="authToken" nillable="true" type="xs:string"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:element name="closeResponse">
            <xs:complexType>
               <xs:sequence>
                  <xs:element name="return" type="xs:boolean"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
      </xs:schema>
   </wsdl:types>
   <wsdl:message name="closeRequest">
      <wsdl:part name="parameters" element="ns:close"/>
   </wsdl:message>
   <wsdl:message name="closeResponse">
      <wsdl:part name="parameters" element="ns:closeResponse"/>
   </wsdl:message>
   <wsdl:portType name="vish_testweb_closePortType">
      <wsdl:operation name="close">
         <wsdl:input message="ns:closeRequest" wsaw:Action="urn:close"/>
         <wsdl:output message="ns:closeResponse" wsaw:Action="urn:closeResponse"/>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="vish_testweb_closeSoap11Binding" type="ns:vish_testweb_closePortType">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
      <wsdl:operation name="close">
         <soap:operation soapAction="urn:close" style="document"/>
         <wsdl:input>
            <soap:body use="literal"/>
         </wsdl:input>
         <wsdl:output>
            <soap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:binding name="vish_testweb_closeSoap12Binding" type="ns:vish_testweb_closePortType">
      <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
      <wsdl:operation name="close">
         <soap12:operation soapAction="urn:close" style="document"/>
         <wsdl:input>
            <soap12:body use="literal"/>
         </wsdl:input>
         <wsdl:output>
            <soap12:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:binding name="vish_testweb_closeHttpBinding" type="ns:vish_testweb_closePortType">
      <http:binding verb="POST"/>
      <wsdl:operation name="close">
         <http:operation location="close"/>
         <wsdl:input>
            <mime:content type="application/xml" part="parameters"/>
         </wsdl:input>
         <wsdl:output>
            <mime:content type="application/xml" part="parameters"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="vish_testweb_close">
      <wsdl:port name="vish_testweb_closeHttpsSoap11Endpoint" binding="ns:vish_testweb_closeSoap11Binding">
         <soap:address location=""/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_closeHttpSoap11Endpoint" binding="ns:vish_testweb_closeSoap11Binding">
         <soap:address location="http://localhost:8080/vish-800_latest/services/vish_testweb_close.vish_testweb_closeHttpSoap11Endpoint/"/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_closeHttpSoap12Endpoint" binding="ns:vish_testweb_closeSoap12Binding">
         <soap12:address location="http://localhost:8080/vish-800_latest/services/vish_testweb_close.vish_testweb_closeHttpSoap12Endpoint/"/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_closeHttpsSoap12Endpoint" binding="ns:vish_testweb_closeSoap12Binding">
         <soap12:address location=""/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_closeHttpsEndpoint" binding="ns:vish_testweb_closeHttpBinding">
         <http:address location=""/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_closeHttpEndpoint" binding="ns:vish_testweb_closeHttpBinding">
         <http:address location="http://localhost:8080/vish-800_latest/services/vish_testweb_close.vish_testweb_closeHttpEndpoint/"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

我正在尝试以 RESTFUL 样式调用上述 Web 服务。

http://localhost:8080/LabWare-800_latest/services/labware_weblims_close/close

数据以应用程序/json 格式作为 POST 发送:

{
    "close": {
        "authToken":"authtoken1112334"
    }
}

但是轴机械抛出以下“故障”

{"Fault": "<soapenv:Fault xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><faultcode>soapenv:Server<\/faultcode><faultstring>namespace mismatch require vish_testweb_close found vish_testweb_authenticate<\/faultstring><detail/><\/soapenv:Fault>"}

命名空间还有另一个 Web 服务 : vish_testweb_authenticate。以下是 wsdl :

<wsdl:definitions targetNamespace="vish_testweb_authenticate" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="vish_testweb_authenticate" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl">
   <wsdl:documentation>vish_testweb_authenticate</wsdl:documentation>
   <wsdl:types>
      <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="vish_testweb_authenticate">
         <xs:element name="authenticateWithRole">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" name="username" nillable="true" type="xs:string"/>
                  <xs:element minOccurs="0" name="password" nillable="true" type="xs:string"/>
                  <xs:element minOccurs="0" name="role" nillable="true" type="xs:string"/>
                  <xs:element minOccurs="0" name="limsDSName" nillable="true" type="xs:string"/>
                  <xs:element minOccurs="0" name="limsServiceName" nillable="true" type="xs:string"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:element name="authenticateWithRoleResponse">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:element name="authenticate">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" name="username" nillable="true" type="xs:string"/>
                  <xs:element minOccurs="0" name="password" nillable="true" type="xs:string"/>
                  <xs:element minOccurs="0" name="limsDSName" nillable="true" type="xs:string"/>
                  <xs:element minOccurs="0" name="limsServiceName" nillable="true" type="xs:string"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:element name="authenticateResponse">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
      </xs:schema>
   </wsdl:types>
   <wsdl:message name="authenticateRequest">
      <wsdl:part name="parameters" element="ns:authenticate"/>
   </wsdl:message>
   <wsdl:message name="authenticateResponse">
      <wsdl:part name="parameters" element="ns:authenticateResponse"/>
   </wsdl:message>
   <wsdl:message name="authenticateWithRoleRequest">
      <wsdl:part name="parameters" element="ns:authenticateWithRole"/>
   </wsdl:message>
   <wsdl:message name="authenticateWithRoleResponse">
      <wsdl:part name="parameters" element="ns:authenticateWithRoleResponse"/>
   </wsdl:message>
   <wsdl:portType name="vish_testweb_authenticatePortType">
      <wsdl:operation name="authenticate">
         <wsdl:input message="ns:authenticateRequest" wsaw:Action="urn:authenticate"/>
         <wsdl:output message="ns:authenticateResponse" wsaw:Action="urn:authenticateResponse"/>
      </wsdl:operation>
      <wsdl:operation name="authenticateWithRole">
         <wsdl:input message="ns:authenticateWithRoleRequest" wsaw:Action="urn:authenticateWithRole"/>
         <wsdl:output message="ns:authenticateWithRoleResponse" wsaw:Action="urn:authenticateWithRoleResponse"/>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="vish_testweb_authenticateSoap11Binding" type="ns:vish_testweb_authenticatePortType">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
      <wsdl:operation name="authenticate">
         <soap:operation soapAction="urn:authenticate" style="document"/>
         <wsdl:input>
            <soap:body use="literal"/>
         </wsdl:input>
         <wsdl:output>
            <soap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
      <wsdl:operation name="authenticateWithRole">
         <soap:operation soapAction="urn:authenticateWithRole" style="document"/>
         <wsdl:input>
            <soap:body use="literal"/>
         </wsdl:input>
         <wsdl:output>
            <soap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:binding name="vish_testweb_authenticateSoap12Binding" type="ns:vish_testweb_authenticatePortType">
      <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
      <wsdl:operation name="authenticate">
         <soap12:operation soapAction="urn:authenticate" style="document"/>
         <wsdl:input>
            <soap12:body use="literal"/>
         </wsdl:input>
         <wsdl:output>
            <soap12:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
      <wsdl:operation name="authenticateWithRole">
         <soap12:operation soapAction="urn:authenticateWithRole" style="document"/>
         <wsdl:input>
            <soap12:body use="literal"/>
         </wsdl:input>
         <wsdl:output>
            <soap12:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:binding name="vish_testweb_authenticateHttpBinding" type="ns:vish_testweb_authenticatePortType">
      <http:binding verb="POST"/>
      <wsdl:operation name="authenticate">
         <http:operation location="authenticate"/>
         <wsdl:input>
            <mime:content type="application/xml" part="parameters"/>
         </wsdl:input>
         <wsdl:output>
            <mime:content type="application/xml" part="parameters"/>
         </wsdl:output>
      </wsdl:operation>
      <wsdl:operation name="authenticateWithRole">
         <http:operation location="authenticateWithRole"/>
         <wsdl:input>
            <mime:content type="application/xml" part="parameters"/>
         </wsdl:input>
         <wsdl:output>
            <mime:content type="application/xml" part="parameters"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="vish_testweb_authenticate">
      <wsdl:port name="vish_testweb_authenticateHttpSoap11Endpoint" binding="ns:vish_testweb_authenticateSoap11Binding">
         <soap:address location="http://localhost:8080/vish-800_latest/services/vish_testweb_authenticate.vish_testweb_authenticateHttpSoap11Endpoint/"/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_authenticateHttpsSoap11Endpoint" binding="ns:vish_testweb_authenticateSoap11Binding">
         <soap:address location=""/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_authenticateHttpsSoap12Endpoint" binding="ns:vish_testweb_authenticateSoap12Binding">
         <soap12:address location=""/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_authenticateHttpSoap12Endpoint" binding="ns:vish_testweb_authenticateSoap12Binding">
         <soap12:address location="http://localhost:8080/vish-800_latest/services/vish_testweb_authenticate.vish_testweb_authenticateHttpSoap12Endpoint/"/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_authenticateHttpEndpoint" binding="ns:vish_testweb_authenticateHttpBinding">
         <http:address location="http://localhost:8080/vish-800_latest/services/vish_testweb_authenticate.vish_testweb_authenticateHttpEndpoint/"/>
      </wsdl:port>
      <wsdl:port name="vish_testweb_authenticateHttpsEndpoint" binding="ns:vish_testweb_authenticateHttpBinding">
         <http:address location=""/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

在这方面的任何帮助将不胜感激。

标签: web-servicesaxis2

解决方案


终于解决了问题。问题出在 close.aar 服务的 services.xml 中(这两个服务都已部署为存档。

services.xml 在关闭服务 service.xml 中错误地将 xmlNamespace 设置为“vish_testweb_authenticate”

<service name="vish_testweb_close" targetNamespace="vish_testweb_close">
   <description>
        This service is to close connection
   </description>
   <schema schemaNamespace="labware_weblims_close"/>
   <parameter name="ServiceClass">vish.web.ws.service.CloseService</parameter>
    <parameter name="xmlToJsonNamespaceMap">
        <mappings>
            <mapping xmlNamespace="vish_testweb_authenticate" jsonNamespace=""/>
        </mappings>
    </parameter>
   <operation name="close">
        <messageReceiver  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
       <messageReceiver class="org.apache.axis2.json.gson.rpc.JsonRpcMessageReceiver"/>
   </operation>
   <module ref="soapmonitor"/>
 </service>
 

更正的 service.xml 如下(请参考 'xmlToJsonNamespaceMap' 部分)

<service name="vish_testweb_close" targetNamespace="vish_testweb_close">
   <description>
        This service is to close connection
   </description>
   <schema schemaNamespace="labware_weblims_close"/>
   <parameter name="ServiceClass">vish.web.ws.service.CloseService</parameter>
    <parameter name="xmlToJsonNamespaceMap">
        <mappings>
            <mapping xmlNamespace="vish_testweb_close" jsonNamespace=""/>
        </mappings>
    </parameter>
   <operation name="close">
        <messageReceiver  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
       <messageReceiver class="org.apache.axis2.json.gson.rpc.JsonRpcMessageReceiver"/>
   </operation>
   <module ref="soapmonitor"/>
 </service>

推荐阅读