How to make a PHP SOAP call using the SoapClient class

后端 未结 12 578
星月不相逢
星月不相逢 2020-11-22 17:28

I\'m used to writing PHP code, but do not often use Object-Oriented coding. I now need to interact with SOAP (as a client) and am not able to get the syntax right. I\'ve got

12条回答
  •  有刺的猬
    2020-11-22 17:35

    If you create the object of SoapParam, This will resolve your problem. Create a class and map it with object type given by WebService, Initialize the values and send in the request. See the sample below.

    struct Contact {
    
        function Contact ($pid, $pname)
        {
          id = $pid;
          name = $pname;
      }
    }
    
    $struct = new Contact(100,"John");
    
    $soapstruct = new SoapVar($struct, SOAP_ENC_OBJECT, "Contact","http://soapinterop.org/xsd");
    
    $ContactParam = new SoapParam($soapstruct, "Contact")
    
    $response = $client->Function1($ContactParam);
    

提交回复
热议问题