I have a script that should connect to webservice using WS-Security. Currently, in my script, I have built soap XML and sent it to the webservice endpoint, but I get an xml response with the message "Internal client error".
Here is the code I'm using:
<?php function sendXMLRequest($url, $params) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/soap+xml")); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); ob_start(); $response = curl_exec($ch); $info = curl_getinfo($ch); if ($response === false || $info['http_code'] != 200) { $output = "No cURL data returned for $url [". $info['http_code']. "]"; if (curl_error($ch)) $output .= "\n". curl_error($ch); $response .= $output; } ob_end_clean(); curl_close($ch); return $response; } /* $currentTime = time(); $timestamp = gmdate('Ymd\TH:i:s', $currentTime).'Z'; $nonce = mt_rand(); $non = base64_encode(pack('H*',$nonce)); */ $username = 'derek'; $password = 'Momentum1'; $wsdl = "http://localhost/test/wsdl-src/CRMLeadService.wsdl"; $momurl = "https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0/"; echo("Post to URL: {$momurl}\n"); $xml = '<?xml version="1.0" encoding="utf-8"?>'; $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">'; $xml .= '<soapenv:Header>'; $xml .= '<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">'; $xml .= '<wsse:UsernameToken wsu:Id="UsernameToken-45">'; $xml .= '<wsse:Username>'.$username.'</wsse:Username>'; $xml .= '<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</wsse:Password>'; $xml .= '</wsse:UsernameToken>'; $xml .= '</wsse:Security>'; $xml .= '</soapenv:Header>'; $xml .= '<soapenv:Body>'; $xml .= '<v1:CreateLeadRequest>'; $xml .= '<createLead>'; $xml .= '<v11:LeadSourceId>23627e70-a29e-e211-b8a8-005056b81ebe</v11:LeadSourceId>'; $xml .= '<v11:AffiliateLeadReference>852800020</v11:AffiliateLeadReference>'; $xml .= '<v11:Title>'; $xml .= '<v12:Code>852800018</v12:Code>'; $xml .= '</v11:Title>'; $xml .= '<v11:Initials>MD</v11:Initials>'; $xml .= '<v11:PreferredName>Marius</v11:PreferredName>'; $xml .= '<v11:FirstName>Marius</v11:FirstName>'; $xml .= '<v11:LastName>Drew</v11:LastName>'; $xml .= '<v11:PreferredCorrespondenceLanguage>'; $xml .= '<v13:Code>852800001</v13:Code>'; $xml .= '</v11:PreferredCorrespondenceLanguage>'; $xml .= '<v11:PreferredCommunicationMethod>'; $xml .= '<v14:Code>852800000</v14:Code>'; $xml .= '</v11:PreferredCommunicationMethod>'; $xml .= '<v11:Campaign>'; $xml .= '<v15:Code>95D9042A-440E-E311-A5EB-005056B81EA5</v15:Code>'; $xml .= '</v11:Campaign>'; $xml .= '<v11:HomePhoneNumber>0723621762</v11:HomePhoneNumber>'; $xml .= '<v11:BusinessPhoneNumber>0723621762</v11:BusinessPhoneNumber>'; $xml .= '<v11:MobilePhoneNumber>0723621762</v11:MobilePhoneNumber>'; $xml .= '<v11:EmailAddress> mdrew@gmail.com </v11:EmailAddress>'; $xml .= '<v11:Notes>IMU</v11:Notes><v11:ProductCategories>'; $xml .= '<v16:Code>d000083d-229c-e211-b8a8-005056b81ebe</v16:Code>'; $xml .= '</v11:ProductCategories>'; $xml .= '</createLead>'; $xml .= '</v1:CreateLeadRequest>'; $xml .= '</soapenv:Body>'; $xml .= '</soapenv:Envelope>'; echo $resp = sendXMLRequest($momurl, $xml); ?>
When I searched on the Internet, I found this library called wse-php , and I think I could definitely use this. The problem is that I do not know the hoe to use it. There is not much information on how to use it. Maybe someone here has already used this ... please help. Thanks.
PS: Here is a link to the WSDL and XSD files, if you need them:
http://sdrv.ms/16KC8o4
source share