2

我很难对 web 服务进行 SOAP 调用,WSDL 看起来像这样:

<wsdl:definitions name="Service" targetNamespace="/Service/">
    <wsdl:types>
        <xsd:schema targetNamespace="/#/">
        <xsd:element name="authToken">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="username" type="xsd:string"/>
                    <xsd:element name="password" type="xsd:string"/>
                </xsd:sequence>
           </xsd:complexType>
        </xsd:element>
        <xsd:element name="fault">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="faultType">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:enumeration value="REQUIRED"/>
                                <xsd:enumeration value="INVALID"/>
                           </xsd:restriction>
                        </xsd:simpleType>
                   </xsd:element>
                   <xsd:element name="faultData" type="xsd:string"/>
               </xsd:sequence>
           </xsd:complexType>
        </xsd:element>
        <xsd:simpleType name="param1">
            <xsd:restriction base="xsd:int"/>
        </xsd:simpleType>
        <xsd:simpleType name="param2">
            <xsd:restriction base="xsd:int"/>
        </xsd:simpleType>
        <xsd:simpleType name="param3">
            <xsd:restriction base="xsd:int"/>
        </xsd:simpleType>
        <xsd:element name="Add">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element ref="tns:authToken"/>
                        <xsd:element name="param1" type="tns:param1"/>
                       <xsd:element name="param2" type="tns:param2"/>
                       <xsd:element name="param3" type="tns:param3"/>
                        <xsd:choice>
                            <xsd:element name="Name">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="first" type="tns:namefirst"/>
                                        <xsd:element name="last" type="tns:namelast"/>
                                    </xsd:sequence>
                                </xsd:complexType>
                            </xsd:element>
....

然后使用 XML:Compile,我执行以下操作

use XML::Compile::WSDL11;
use XML::Compile::SOAP11;
use XML::Compile::Transport::SOAPHTTP;
my $wsdlXml = XML::LibXML->new->parse_file("pathtowsdl");
my $wsdl = XML::Compile::WSDL11->new($wsdlXml);
my $call = $wsdl->compileClient('Add');
my %param = ('authToken'    =>  {
                    'username'  =>  'xxx',
                    'password'  =>  'xxxx',
                    },
             'param1'   =>  'xxx',
             'param2'   =>  'xxxx',
             'param3'   =>  'xxxx',
             'Name'     =>  {
                'first' =>  'xxx',
                'last'  =>  'xxx',
              });
my ($response, $trace) = $call->(\%params);

我从上面得到一个错误:

解组错误:意外元素(uri:“”,本地:“authToken”)

如果我取出“authToken”,那么我会得到“错误:元素 `authToken' 缺少所需值”的本地错误。

我认为我的参数结构是错误的,但我不确定它应该是什么。有任何想法吗?

TIA

4

0 回答 0