Php调用Soap函数并传递数据

时间:2011-09-25 14:59:02

标签: php soap soap-client

我尝试在我的应用程序中启动一个简单的Soap调用。

肥皂网络服务位于:' http://www.asd.com?wsdl'

Soap Web Service公开方法:upload(),到Ws upload()方法我可以传递一个字符串数据:' arg0'

所以我的代码如下所示:

        $wsdl = "http://www.asd.com?wsdl";
        $ws = new SoapClient($wsdl);
        $vem = $ws->__soapCall('upload', array('arg0'=>'sgfsg'));

似乎WS方法收到arg0 = NULL,这个PHP代码好吗?

WS wsdl

      <wsdl:definitions name="aWS" targetNamespace="http://validator.aWS.it/">
<wsdl:import location="http://asd.com/aWS?wsdl=aWSDL.wsdl" namespace="http://interfaces.aWS.it/">
    </wsdl:import><wsdl:binding name="aWSSoapBinding" type="ns1:...">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Upload">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="Upload">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="UploadResponse"><soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ping">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="ping">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="pingResponse">
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="NonBlockingExecption">
<soap:fault name="NonBlockingExecption" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="aWS">
<wsdl:port binding="tns:aWSSoapBinding" name="aWSPort">
<soap:address location="http://asd.com/aWS"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

wsdl类型

    <wsdl:definitions name="aWS" targetNamespace="http://interfaces.aWS.it/">
<wsdl:types>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://interfaces.aWS.it/">
<xs:element name="Upload" type="tns:Upload"/>
<xs:element name="UploadResponse" type="tns:UploadResponse"/>
<xs:element name="ping" type="tns:ping"/>
<xs:element name="pingResponse" type="tns:pingResponse"/>
<xs:complexType name="Upload">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="UploadResponse">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="ping">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="pingResponse">
<xs:sequence>
<xs:element name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="NonBlockingExecption">
<xs:sequence/>
</xs:complexType>
<xs:element name="NonBlockingExecption" type="tns:NonBlockingExecption"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="NonBlockingExecption">
<wsdl:part element="ns1:NonBlockingExecption" name="NonBlockingExecption">
</wsdl:part>
</wsdl:message>
<wsdl:message name="Upload">
<wsdl:part element="ns1:Upload" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="pingResponse">
<wsdl:part element="ns1:pingResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="ping">
<wsdl:part element="ns1:ping" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="UploadResponse">
<wsdl:part element="ns1:UploadResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="aWS">
<wsdl:operation name="Upload">
<wsdl:input message="ns1:Upload" name="Upload">
</wsdl:input>
<wsdl:output message="ns1:UploadResponse" name="UploadResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ping">
<wsdl:input message="ns1:ping" name="ping">
</wsdl:input>
<wsdl:output message="ns1:pingResponse" name="pingResponse">
</wsdl:output>
<wsdl:fault message="ns1:NonBlockingExecption" name="NonBlockingExecption">
</wsdl:fault>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>

1 个答案:

答案 0 :(得分:1)

尝试使用:

更改soap方法调用(第三条指令)

$ vem = $ ws-&gt; upload(“sgfsg”);

通常在WSDL模式下,soap函数被调用为Soap Client对象的方法,而不是使用soapCall。

我试图打开http://www.asd.com?wsdl,但我看不到任何wsdl代码。

如果操作上传只需要一个字符串作为参数,则可以在不构建数组的情况下传递它。