Exemple
$url = 'http://somedomain/file.wsdl'; $client = new SoapClient($url, array('trace'=>1, 'exception'=>1)); $auth = array('ID'=>'', 'MDP'=>''); $header = new SoapHeader('http://somedomain/', 'CredentialHeader', $auth, false); $client->__setSoapHeaders($header); $result = $client->methodName(array( 'param1'=>'', 'param2'=>0 )); var_dump($result);
WSDL
<wsdl:definitions targetNamespace="http://somedomain/" xmlns:tns="http://somedomain/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" > <wsdl:types> <s:schema elementFormDefault="qualified" targetNamespace="http://somedomain/"> <s:element name="CredentialHeader" type="tns:CredentialHeader"/> <s:complexType name="CredentialHeader"> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="ID" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="MDP" type="s:string"/> </s:sequence> <s:anyAttribute/> </s:complexType> </s:schema> <s:element name="methodName"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="param1" type="s:string"/> <s:element minOccurs="1" maxOccurs="1" name="param2" type="s:int"/> </s:sequence> </s:complexType> </s:element> <s:element name="methodNameResponse"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="methodNameResult" type="tns:someType1"/> </s:sequence> </s:complexType> </s:element> <s:complexType name="someType1"> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="param1" type="s:boolean"/> <s:element minOccurs="0" maxOccurs="1" name="param2" type="tns:ArrayOfType2"/> </s:sequence> </s:complexType> <s:complexType name="ArrayOfType2"> <s:sequence> <s:element minOccurs="0" maxOccurs="unbounded" name="Type2" nillable="true" type="tns:Type2"/> </s:sequence> </s:complexType> <s:complexType name="Type2"> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="param1" type="s:string"/> <s:element minOccurs="0" maxOccurs="1" name="param2" type="s:string"/> </s:sequence> </s:complexType> </wsdl:types> <wsdl:message name="methodNameSoapIn"> <wsdl:part name="parameters" element="tns:methodName"/> </wsdl:message> <wsdl:message name="methodNameSoapOut"> <wsdl:part name="parameters" element="tns:methodNameResponse"/> </wsdl:message> <wsdl:message name="methodNameCredentialHeader"> <wsdl:part name="CredentialHeader" element="tns:CredentialHeader"/> </wsdl:message> <wsdl:portType name="ServiceSoap"> <wsdl:operation name="methodName"> <wsdl:input message="tns:methodNameSoapIn"/> <wsdl:output message="tns:methodNameSoapOut"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="ServiceSoap" type="tns:ServiceSoap"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="methodName"> <soap:operation soapAction="http://somedomain/methodName" style="document"/> <wsdl:input> <soap:body use="literal"/> <soap:header message="tns:methodNameCredentialHeader" part="CredentialHeader" use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> </wsdl:defintions>
Exemple du format de la réponse
class stdClass { class methodNameResult [someType1] { boolean param1; class param2 [ArrayOfType2] { array Type2 ( class Type2 { string param1; string param2; }, class Type2 { string param1; string param2; }, class Type2 { string param1; string param2; }, ) } } }
Dernière modification: 2013-08-03 09:59:49 par Yan Morin
Hébergé par ProgYSM