La richiesta SOAP del servizio Web sta funzionando su SOAPUI ma non funziona su PHP

Ho provato quasi tutte le possibili soluzioni che ho trovato ma non riesco a far funzionare questo script. Ecco alcuni dei miei precedenti tentativi:

Come utilizzare la libreria wse-php per connettersi ai servizi Web protetti tramite SOAP

https://stackoverflow.com/questions/18952222/soap-error-encoding-object-has-no-createlead-property-php

Come risolvere l'errore: SOAP-ERROR: Encoding: l'object non ha la properties; 'createLead'?

Come consumare un servizio Web protetto con WS-Security tramite SOAP [PHP]?

Ecco il mio ultimo tentativo:

<?php try { $username = 'derek'; $password = 'Momentum1'; $url = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0/"; $xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.momentum.co.za/crm/service/application/CRMLeadService/v1.0" xmlns:v11="http://www.momentum.co.za/crm/service/type/application/Lead/v1.0" xmlns:v12="http://www.momentum.co.za/crm/service/type/TitleType/v1.0" xmlns:v13="http://www.momentum.co.za/crm/service/type/LanguageType/v1.0" xmlns:v14="http://www.momentum.co.za/crm/service/type/PreferredContactMethodType/v1.0" xmlns:v15="http://www.momentum.co.za/crm/service/type/CampaignType/v1.0" xmlns:v16="http://www.momentum.co.za/crm/service/type/ProductCategoryType/v1.0"> <soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsse:UsernameToken> <wsse:Username>derek</wsse:Username> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Momentum1</wsse:Password> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <v1:CreateLeadRequest> <createLead> <v11:LeadSourceId>23627e70-a29e-e211-b8a8-005056b81ebe</v11:LeadSourceId> <v11:AffiliateLeadReference>852800020</v11:AffiliateLeadReference> <v11:Title> <v12:Code>852800018</v12:Code> </v11:Title> <v11:Initials>MD</v11:Initials> <v11:PreferredName>Marius</v11:PreferredName> <v11:FirstName>Marius</v11:FirstName> <v11:LastName>Drew</v11:LastName> <v11:PreferredCorrespondenceLanguage> <v13:Code>852800001</v13:Code> <v13:Description>?</v13:Description> </v11:PreferredCorrespondenceLanguage> <v11:PreferredCommunicationMethod> <v14:Code>852800000</v14:Code> </v11:PreferredCommunicationMethod> <v11:Campaign> <v15:Code>95D9042A-440E-E311-A5EB-005056B81EA5</v15:Code> </v11:Campaign> <v11:HomePhoneNumber>0723621762</v11:HomePhoneNumber> <v11:BusinessPhoneNumber>0723621762</v11:BusinessPhoneNumber> <v11:MobilePhoneNumber>0723621762</v11:MobilePhoneNumber> <v11:EmailAddress>[email protected]</v11:EmailAddress> <v11:Notes>IMU</v11:Notes> <v11:ProductCategories> <v16:Code>d000083d-229c-e211-b8a8-005056b81ebe</v16:Code> </v11:ProductCategories> </createLead> </v1:CreateLeadRequest> </soapenv:Body> </soapenv:Envelope>'; $content = utf8_encode($xml); $content_length = strlen($xml); $headers = arrays('Content-Type: application/soap+xml; charset=utf-8', 'Content-Length: ' . $content_length); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt ($ch, CURLOPT_POSTFIELDS, $content); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $output = curl_exec($ch); curl_close($ch); print $output; } catch (Exception $e) { var_dump($e); } ?> 

Penso che ci sia qualcosa di sbagliato nel modo in cui invio il mio messaggio. È ansible che il problema sia il mio WSDL e la sua posizione?

Ci sto già lavorando da una settimana e mi sento già frustrato. Questa roba WS-Security è un dolore. Ho provato ad utilizzare i suggerimenti qui su StackOverflow come la creazione di una class che si estende a SoapClient ma che comunque non ha funzionato. Spero che qualcuno possa essere angelo e aiutarmi con questo. Grazie!

Oh, a proposito, ecco la richiesta di messaggio XML RAW su SOAPUI:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.momentum.co.za/crm/service/application/CRMLeadService/v1.0" xmlns:v11="http://www.momentum.co.za/crm/service/type/application/Lead/v1.0" xmlns:v12="http://www.momentum.co.za/crm/service/type/TitleType/v1.0" xmlns:v13="http://www.momentum.co.za/crm/service/type/LanguageType/v1.0" xmlns:v14="http://www.momentum.co.za/crm/service/type/PreferredContactMethodType/v1.0" xmlns:v15="http://www.momentum.co.za/crm/service/type/CampaignType/v1.0" xmlns:v16="http://www.momentum.co.za/crm/service/type/ProductCategoryType/v1.0"> <soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsse:UsernameToken> <wsse:Username>817221</wsse:Username> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">1234</wsse:Password> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <v1:CreateLeadRequest> <createLead> <v11:LeadSourceId>23627e70-a29e-e211-b8a8-005056b81ebe</v11:LeadSourceId> <v11:AffiliateLeadReference>852800020</v11:AffiliateLeadReference> <v11:Title> <v12:Code>852800018</v12:Code> </v11:Title> <v11:Initials>MD</v11:Initials> <v11:PreferredName>Marius</v11:PreferredName> <v11:FirstName>Marius</v11:FirstName> <v11:LastName>Drew</v11:LastName> <v11:PreferredCorrespondenceLanguage> <v13:Code>852800001</v13:Code> <v13:Description>?</v13:Description> </v11:PreferredCorrespondenceLanguage> <v11:PreferredCommunicationMethod> <v14:Code>852800000</v14:Code> </v11:PreferredCommunicationMethod> <v11:Campaign> <v15:Code>95D9042A-440E-E311-A5EB-005056B81EA5</v15:Code> </v11:Campaign> <v11:HomePhoneNumber>0723621762</v11:HomePhoneNumber> <v11:BusinessPhoneNumber>0723621762</v11:BusinessPhoneNumber> <v11:MobilePhoneNumber>0723621762</v11:MobilePhoneNumber> <v11:EmailAddress>[email protected]</v11:EmailAddress> <v11:Notes>IMU</v11:Notes> <v11:ProductCategories> <v16:Code>d000083d-229c-e211-b8a8-005056b81ebe</v16:Code> </v11:ProductCategories> </createLead> </v1:CreateLeadRequest> </soapenv:Body> </soapenv:Envelope> 

Funziona perfettamente su SOAPUI ma restituisce un soapenv: Client Internal Error su PHP.

Ecco un'altra versione della sceneggiatura che ho realizzato. Comunque continua a dare un errore interno. Forse c'è un problema con la costruzione dell'intestazione che si occupa di WS-Security sul servizio web.

 <?php $wsdl = "http://imupost.co.za/momentumcrm/CRMLeadServiceV10.wsdl"; $momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0/"; echo("Post to URL: {$momurl}\n"); $username = "derek"; $password = "Momentum1"; echo("<pre>\n"); $client = new SoapClient ($wsdl, arrays('location' => $momurl, 'style' => SOAP_DOCUMENT, 'trace' => true, 'soap_version' => SOAP_1_1, 'exceptions' => true, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP)); $header=' <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsse:UsernameToken wsu:Id="UsernameToken-45"> <wsse:Username>'.$username.'</wsse:Username> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</wsse:Password> </wsse:UsernameToken> </wsse:Security> '; echo("<pre>\n"); $headerSoapVar = new SoapVar($header,XSD_ANYXML); $soapheader = new SoapHeader('wsse', "Security" , $headerSoapVar , true); $client->__setSoapHeaders($soapheader); $params['createLead'] = arrays( 'LeadSourceId' => '23627e70-a29e-e211-b8a8-005056b81ebe', 'AffiliateLeadReference' => '852800020', 'Title' => arrays('Code' => '852800018'), 'Initials' => 'MD', 'PreferredName' => 'Marius', 'FirstName' => 'Marius', 'LastName' => 'Drew', 'PreferredCorrespondenceLanguage' => arrays('Code' => '852800001'), 'PreferredCommunicationMethod' => arrays('Code' =>'852800000'), 'Campaign' => arrays('Code' => '95D9042A-440E-E311-A5EB-005056B81EA5'), 'HomePhoneNumber' => '0723621762', 'BusinessPhoneNumber' => '0723621762', 'MobilePhoneNumber' => '0723621762', 'EmailAddress' => '[email protected]', 'Notes' => 'IMU', 'ProductCategories' => arrays('Code' => 'd000083d-229c-e211-b8a8-005056b81ebe') ); try { echo $result = $client->__call("createLead", arrays($params)); echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n"; echo "REQUEST:\n" . $client->__getLastRequestHeaders() . "\n"; } catch (Exception $e) { $ml = new SimpleXMLElement($client->__getLastRequest()); $ml->asXML('new.xml'); echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n"; echo "REQUEST:\n" . $client->__getLastRequestHeaders() . "\n"; $msgs = $e->getMessage(); echo "Error: $msgs"; } ?> 

Eventuali suggerimenti? Avevo davvero bisogno del tuo aiuto. Grazie!

Usando SoapClient , questo dovrebbe darti un'idea di come creare la chiamata SOAP:

 try { $client = new SoapClient('CRMLeadServiceV10.wsdl'); $header = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', arrays( 'UsernameToken' => arrays( 'Username' => 817221, 'Password' => arrays( '_' => 1234, 'Type' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')))); $params = new stdClass(); $params->createLead = new stdClass(); $params->createLead->LeadSourceId = 1234; $result = $client->__soapCall('createLead', $params, null, $header); print_r($result); } catch (SoapFault $e) { die($e->getMessage()); } 

Sono stato in grado di connettermi al webservice usando il seguente codice:

 $client = new SoapClient ($wsdl, arrays('location' => $momurl, 'action'=>$action, 'style' => SOAP_DOCUMENT, 'trace' => 1, 'soap_version' => SOAP_1_1, 'exceptions' => false, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'ssl_method' => SOAP_SSL_METHOD_TLS)); $header='<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsse:UsernameToken wsu:Id="UsernameToken-45"> <wsse:Username>'.$usname.'</wsse:Username> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</wsse:Password> </wsse:UsernameToken> </wsse:Security>'; $headerSoapVar = new SoapVar($header,XSD_ANYXML); $soapheader = new SoapHeader('wsse', "Security" , $headerSoapVar , true); $client->__setSoapHeaders($soapheader); $params['/* the function or method that you want to use */'] = arrays(/* insert your parameters here */); $result = $client->__soapCall("/* the function or method that you want to use */", $params); 

Controlla la parte intestazione della tua richiesta se è simile alla mia. Se non lo è, usa la tua intestazione. Fondamentalmente, basta copiare la parte di intestazione della tua richiesta e basta impostare le variables per nome utente e password. L'ho provato su un altro webservice e sta funzionando bene.