T
T
tatarrr952018-02-26 21:09:56
PHP
tatarrr95, 2018-02-26 21:09:56

How to write a SOAP request in PHP using a ready-made wsdl?

There is a wsdl file:

<?xml version="1.0"  encoding="UTF-8" ?>
<definitions 
  xmlns="http://schemas.xmlsoap.org/wsdl/" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  name="esia_usl" 
  targetNamespace="urn:TFOMS-EsiaUsl" 
  xmlns:tns="urn:TFOMS-EsiaUsl" 
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"   
  >
<types>
    <xs:schema 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 			
      targetNamespace="urn:TFOMS-EsiaUsl" 
      elementFormDefault="qualified" 
      xmlns:tns="urn:TFOMS-EsiaUsl"
    >	
    <xs:complexType name="InputParams">
      <xs:sequence>
        <xs:element name="fam" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
        <xs:element name="im" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
        <xs:element name="ot" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
        <xs:element name="dr" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
        <xs:element name="dmin" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
        <xs:element name="dmax" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
      </xs:sequence>  
    </xs:complexType>    

    <xs:complexType name="Usl">
      <xs:sequence>
        <xs:element name="lpu" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
        <xs:element name="nmlpu" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>            
        <xs:element name="smo" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>            
        <xs:element name="nmusl" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
        <xs:element name="uslok" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
        <xs:element name="ds" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>                        
        <xs:element name="dtbeg" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>
        <xs:element name="dtend" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element>            
        <xs:element name="sum" type="xs:decimal" minOccurs="1" maxOccurs="1"></xs:element>
      </xs:sequence>  
    </xs:complexType>   

    <xs:complexType name="UslData">
      <xs:sequence>
        <xs:element name="usl" type="tns:Usl" minOccurs="0" maxOccurs="unbounded"></xs:element>
      </xs:sequence>  
    </xs:complexType>   

   </xs:schema> 
</types>      
  <message name="request_msg">
    <part name="input_params" type="tns:InputParams"/>    
  </message>
  <message name="response_msg">
    <part name="usl_list" type="tns:UslData"/>
  </message>  
  <portType name="EsiaUslType">
    <operation name="getUsl">
      <input message="tns:request_msg"/>
      <output message="tns:response_msg"/>
    </operation>   
  </portType>
  <binding name="EsiaUslBinding" type="tns:EsiaUslType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getUsl">
      <soap:operation soapAction="" style="document"/>
      <input>
        <soap:body use="literal"/>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>    
  </binding>
  <service name="EsiaUslService">
    <port name="EsiaUslPort" binding="tns:EsiaUslBinding">
      <soap:address location="http://192.168.10.13/soap/server_esia.php"/>
    </port>
  </service>
</definitions>

Writing:
$client = new SoapClient("http://site/esia.wsdl");
var_dump($client->__getFunctions());

Issues:
array(1) { [0]=> string(41) "UslData getUsl(InputParams $input_params)" }

On var_dump($client->__getTypes()) it gives:
array(3) { 
   [0]=> string(99) "struct InputParams { string fam; string im; string ot; string dr; string dmin; string dmax; }" 
   [1]=> string(141) "struct Usl { string lpu; string nmlpu; string smo; string nmusl; string uslok; string ds; string dtbeg; string dtend; decimal sum; }" 
   [2]=> string(28) "struct UslData { Usl usl; }" }

So, when making a SOAP request, I need to execute the getUsl() function;
What are the correct parameters to pass to this function? Should the parameter be a single InputParams class, or should the parameters be a list of the contents of the InputParams, as in my example below?
$result = $client->getUsl(fam, im, ot, dr, dmin, dmax);

And immediately another question, fam, im, ot should be in Russian. The encoding used by the soap server is utf-8. But the page code and the page itself from which I send this request works in windows-1251 encoding. How to correctly send and execute a request?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question