XML :: Compile :: SOAP并使用WSDL调用Web服务

时间:2012-04-15 16:51:18

标签: perl soap-client

我很难对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:编译,我执行以下操作

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:“”,local:“authToken”)

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

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

TIA

0 个答案:

没有答案