命名空间/无效内容

时间:2016-07-27 16:29:51

标签: savon

我正在使用savon 2.11.1并且无可否认地忘记了更多关于XML Web服务的事情;有以下问题:

client = Savon.client(wsdl: 'http://myhost.com/service?wsdl')
client.operations
=> [:get_user_details_1, :get_all_user_details_1, :set_user_details_1]
client.call(:get_user_details_1, message: { uuid: "ABC" })

这样做了我的错误信息:

Savon::SOAPFault: (S:Client) org.xml.sax.SAXParseException; cvc-elt.1: Cannot find the declaration of element 'xsdws:GetUserDetails'.

仔细观察我看到的实际WSDL声明(为简洁而修剪)

<wsdl:definitions xmlns:ns="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://myhost.com/ns/2008/08/15/webservices/ASUserManagement_1/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsdws="http://myhost.com/ns/2008/08/15/webservices/AccessServices" name="ASUserManagement_1" targetNamespace="http://myhost.com/ns/2008/08/15/webservices/UserManagement/wsdl">
<wsdl:types>
<xs:schema xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://myhost.com/ns/2008/08/15/webservices/AccessServices">
<xs:include schemaLocation="http://myhost.com:80/service/UserManagement?xsd=1"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetUserDetailsInput">
<wsdl:part name="GetUserDetails" element="xsdws:GetUserDetails"/>
</wsdl:message>
</wsdl:message>
<wsdl:message name="GetAllUserDetailsInput">
<wsdl:part name="GetAllUserDetails" element="xsdws:GetAllUserDetails"/>
</wsdl:message>
<wsdl:portType name="ASUserManagement">
<wsdl:operation name="GetUserDetails_1">
<wsdl:input message="tns:GetUserDetailsInput"/>
<wsdl:output message="tns:GetUserDetailsOutput"/>
</wsdl:operation>
<wsdl:operation name="GetAllUserDetails_1">
<wsdl:input message="tns:GetAllUserDetailsInput"/>
<wsdl:output message="tns:GetAllUserDetailsOutput"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ASUserManagementBinding" type="AAA-ASUserManagement">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetUserDetails_1">
<soap:operation soapAction="GetUserDetails_1"/>
<wsdl:input>
<soap:body parts="GetUserDetails" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body parts="GetUserDetailsResponse" use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetAllUserDetails_1">
<soap:operation soapAction="GetAllUserDetails_1"/>
<wsdl:input>
<soap:body parts="GetAllUserDetails" use="literal"/>
</wsdl:input>

所以调整它以包含在xs:schema元素中声明的命名空间:

client = Savon.client(wsdl: 'http://myhost.com/service?wsdl', namespace: 'http://myhost.com/ns/2008/08/15/webservices/AccessServices')
client.call(:get_user_details_1, message: { uuid: "ABC" })
Savon::SOAPFault: (S:Client) org.xml.sax.SAXParseException; cvc-complex-type.2.4.a: Invalid content was found starting with element 'uuid'. One of '{"http://www.reuters.com/ns/2008/08/15/webservices/AAA-AccessServices_1":uuid}' is expected.

不确定我在这里做错了什么 - 来自Fiddler上自动生成的.NET客户端代理代码的示例有效请求如下所示:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetAllUserDetails xmlns="http://myhost.com/ns/2008/08/15/webservices/AccessServices"><uuid>ABC</uuid></GetAllUserDetails></soap:Body></soap:Envelope>

我知道我错了吗?

1 个答案:

答案 0 :(得分:0)

您可以将namespace_identifier和名称空间设置为客户端内的参数,同时具有log_level并记录为true。

Savon.client(
        wsdl: "http://myhost.com/service?wsdl",
        log: true,
        log_level: :debug,
        pretty_print_xml: true,
        namespace_identifier: :xsdws,
        namespaces: {"xmlns:xsdws" => "http://myhost.com/ns/2008/08/15/webservices/AccessServices","xmlns:tns"=>"http://myhost.com/ns/2008/08/15/webservices/ASUserManagement_1/wsdl"}

     )

希望这可以帮助您解决问题。

干杯