XML : PHP SOAP XML schema explanation and troubleshooting

I need to create a SOAP XML schema to connect PHP to SOAP Server. I read about SOAPClient class in PHP docs but it's quite unclear how to actually create an XML Schema like the one I need. I've also read about SOAPVar but I'm not able to make it work, probably because it's the first time that I use PHP SOAP.
The function I'm calling from the server is named insertContact which requires a string password and a Contact object, where source and emailAddress1 are the only mandatory fields.

Anyway, this should be the XML schema:

  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">     <soap:Header>        <ns9:HeaderInfo xmlns:ns9="http://example.com/" xmlns:ns8="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns7="http://tempuri.org/" xmlns:ns6="http://schemas.datacontract.org/2004/07/FileServiceWcfServiceLibrary.Domain" xmlns:ns5="http://example.com.Utilities" xmlns:ns4="http://example.com.Entity" xmlns:ns3="http://example.com" xmlns:ns2="http://example.com.PrimaryKey">           <infos>              <entries>                 <key>apiKey</key>                 <value>key</value>              </entries>              <entries>                 <key>apiSecret</key>                 <value>secret</value>              </entries>           </infos>           <type>source</type>        </ns9:HeaderInfo>     </soap:Header>     <soap:Body>        <ns1:insertContact xmlns:ns1="http://example.com/">           <password xmlns:ns2="http://example.com.PrimaryKey" xmlns:ns3="http://example.com" xmlns:ns4="http://example.com.Entity" xmlns:ns5="http://example.com.Utilities" xmlns:ns6="http://schemas.datacontract.org/2004/07/FileServiceWcfServiceLibrary.Domain" xmlns:ns7="http://tempuri.org/" xmlns:ns8="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns9="http://example.com/">d07m3d1a</password>           <contact xmlns:ns2="http://example.com.PrimaryKey" xmlns:ns3="http://example.com" xmlns:ns4="http://example.com.Entity" xmlns:ns5="http://example.com.Utilities" xmlns:ns6="http://schemas.datacontract.org/2004/07/FileServiceWcfServiceLibrary.Domain" xmlns:ns7="http://tempuri.org/" xmlns:ns8="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns9="http://example.com/">              <ns3:Address1_City xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:Address1_Line1 xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:Address1_PostalCode xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:Address1_StateOrProvince xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:Address1_Telephone1 xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:Birthdate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:Country>                 <ns2:CountryCode>GB</ns2:CountryCode>              </ns3:Country>              <ns3:CreatedBy xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:CreatedOn xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:EmailAddress1>email@example.com</ns3:EmailAddress1>              <ns3:FacebookId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:FirstName>FirstName</ns3:FirstName>              <ns3:FiscalCode xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:GooglePlusId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:Id xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:IdBadgeminton xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:isM xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:isMotoM xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:IsPir xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:IsCar xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:isF1 xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:isMoto></ns3:isMoto>              <ns3:isTyre xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:LangCode>en</ns3:LangCode>              <ns3:LastName>LastName</ns3:LastName>              <ns3:MobilePhone xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:ModifiedBy xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:ModifiedOn xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:NickName xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:Privacy>true</ns3:Privacy>              <ns3:PrivacyGroup>false</ns3:PrivacyGroup>              <ns3:PrivacyThird>false</ns3:PrivacyThird>              <ns3:Source>SoapUI</ns3:Source>              <ns3:StateCode xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:StatusCode xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:SubscriptionConfirmed xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>              <ns3:TwitterId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>           </contact>        </ns1:insertContact>     </soap:Body>  </soap:Envelope>    

I have no idea on how to do this schema, I've just understood how to create Headers, but nothing more at all. This I what I've tried so far:

  $soapClient=new SoapClient(WSDL_URI,array(          'trace' => true,          'login' => 'user',          'password' => 'password'      ));      $soapHeader=new SOAPHeader(API_NAMESPACE,'HeaderInfo',array(          'infos' => array(              'entries' => array(                  'key' => 'apiKey',                  'value' => APIKEY              ),              'entries' => array(                  'key' => 'apiSecret',                  'value' => APISECRET              )          ),          'type' => 'source'      ));      $soapClient->__setSoapHeaders($soapHeader);      $soapContactParams=[];      $soapContactParams[]=new SoapVar('email@example.com',XSD_STRING,null,null,'EmailAddress1');      $soapContactParams[]=new SoapVar('source',XSD_STRING,null,null,'Source');      $soapContact=new SoapVar($soapContactParams,SOAP_ENC_OBJECT,null,null,'contact');      $soapClient->insertContact(password,$soapContact);    

Which is giving me this error:

  Fatal error: Uncaught SoapFault exception: [soap:Server] Fault occurred while processing. in /var/www/example.com/example.com/test/index.php:34 Stack trace: #0 /var/www/example.com/example.com/test/index.php(34): SoapClient->__call('insertContact', Array) #1 /var/www/example.com/example.com/test/index.php(34): SoapClient->insertContact('password', Object(SoapVar)) #2 {main} thrown in /var/www/example.com/example.com/test/index.php on line 34    

I'm actually quite new to PHP SOAP, and let me say it, I don't like it at all. I don't even know if I'm building a well-formatted XML because I can't print it.

Side note: I've tried using SOAP UI, and it's giving me the same error.

No comments:

Post a Comment