I am trying to connect to a Soap Webservice using PHP's SoapClient and I am getting an error below
The SOAP action specified on the message, '', does not match the HTTP
SOAP Action, 'http://tempuri.org/IInDirect/AddProduct'.
Below is my PHP code to connect to the server.
$requestParams = array(
'Password' => 'XXXXXX',
'Username' => 'XXXXXXX',
'AddressLine1' => '52 TEST DRIVE',
'City' => 'JOHANNESBURG',
'DateOfBirth' => '1960-02-10T00:00:00',
'Forename1' => 'Eva',
'Gender' => 'Unknown',
'Province' => 'GAUTENG',
'SouthAfricanID' => '45454545454',
'ProductCode' => '12345'
);
try {
$options = array(
'soap_version' => SOAP_1_2,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout' => 15,
'trace' => true,
'encoding' => 'UTF-8',
'exceptions' => true,
);
$client = new \SoapClient('https://soap.url.com/test.svc?wsdl', $options);
$actionHeader = new \SoapHeader('http://www.w3.org/2005/08/addressing',
'Action',
'http://tempuri.org/IInDirect/AddProduct');
$client->__setSoapHeaders($actionHeader);
} catch (Exception $e) {
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
$response = $client->AddProduct($requestParams);
print_r($response);
Below is the xml
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tusa="http://schemas.datacontract.org/2004/07/Tusa.Services.ConsumerConnect" xmlns:tem="http://tempuri.org/">
<soap:Header>
<AuthenticationCredentials>
<tusa:Password>Password</tusa:Password>
<tusa:Username>Username</tusa:Username>
</AuthenticationCredentials>
</soap:Header>
<soap:Body>
<tem:AddProduct>
<tem:CustomerDetail>
<tusa:AddressLine1>AddressLine1</tusa:AddressLine1>
<tusa:City>City</tusa:City>
<tusa:DateOfBirth>DateOfBirth</tusa:DateOfBirth>
<tusa:Forename1>Forename1</tusa:Forename1>
<tusa:Gender>Gender</tusa:Gender>
<tusa:MaritalStatus>MaritalStatus</tusa:MaritalStatus>
<tusa:Province>Province</tusa:Province>
<tusa:SouthAfricanID>SouthAfricanID</tusa:SouthAfricanID>
<tusa:Suburb>Suburb</tusa:Suburb>
<tusa:Surname>Surname</tusa:Surname>
</tem:CustomerDetail>
<tem:ProductCode>ProductCode</tem:ProductCode>
</tem:AddProduct>
</soap:Body>
</soap:Envelope>
How would i get this to work?
This error message may be caused by missing Action SOAP header.
$actionHeader = new SoapHeader('http://www.w3.org/2005/08/addressing',
'Action',
'http://tempuri.org/IInDirect/AddProduct');
$client->__setSoapHeaders($actionHeader);
Related
i am trying to re-create below soap request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:data="http://test.gbd.chdb.test.net">
<soapenv:Header>
<userId>5647775-b7d7-4a45-9570-654116547654</userId>
</soapenv:Header>
<soapenv:Body>
<data:getPerson>
<!--Optional:-->
<iin>700521700054</iin>
<!--Optional:-->
<consentConfirmed>true</consentConfirmed>
</data:getPerson>
</soapenv:Body>
</soapenv:Envelope>
using below php scrip
$opts = array(some attributes);
$soap_client = new \SoapClient(null,
array(
'location' => 'https://test.test.net/testServices/PersonDetailsImplService',
'uri' => 'http://test.gbd.chdb.test.net',
'login' => 'XXXXXXX',
'password' => 'YYYYYYY',
'cache_wsdl' => WSDL_CACHE_NONE,
'soap_version'=> SOAP_1_1,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => true,
'exceptions' => true,
'stream_context' => stream_context_create($opts)
)
);
$auth = new \stdClass();
$auth->userId = '5647775-b7d7-4a45-9570-654116547654';
$header = new \SoapHeader('http://test.gbd.chdb.test.net', 'Header', $auth);
$soap_client->__setSoapHeaders($header);
$result = $soap_client->getPerson();
Every time i am executing this i am getting response "userId field is missing". Not sure what am i doing wrong as i am setting Header attribute in my script below and setting headers to my SoapClient via __setSoapHeaders.
Been working on it for few days now and went through tons of articles online - still no go. Any help will be hightly appriciated.
I'm attempting to connect with a WS via Soap and struggling with a content type error when I call the method: content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'
Below is my code, reducing number of params and hiding url, user and password.
The error happens when I call the ClientRegist() function. I'm convinced I have to pass $params in a different way, but can't find an example anywhere.
$url = 'http://---';
$ctx_opts = array(
'http' => array(
'header' => 'Content-Type: application/soap+xml'
),
'username' => '---',
'password' => '---',
'trace' => true,
'exceptions' => true
);
$ctx = stream_context_create($ctx_opts);
$client = new SoapClient($url, array('stream_context' => $ctx));
$params = array(
'Cardnumber' => $number,
'Name' => $name
);
try {
$client = new SoapClient($url, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->ClientRegist($params);
}
catch (Exception $e) {
echo "Error!<br>";
echo $e -> getMessage ().'<br>';
echo 'Last response: '. $client->__getLastResponse();
}
var_dump($response);
Try SOAP version 1.2. Its default Content-Type is application/soap+xml
<?php
// ...
$client = new SoapClient(
$url,
array(
'soap_version' => SOAP_1_2, // !!!!!!!
'stream_context' => $ctx
)
);
Im struggling with this 2 days and trying almost everything I found on internet. I have SOAP service with username and password in header securityContext but have no idea how to provide data in that form in PHP?
This is required header XML:
<soap:Header>
<SecurityContext xmlns="http://tempuri.org/">
<userName>string</userName>
<password>string</password>
</SecurityContext>
</soap:Header>
Huh, i managed it to work. Here is what is necessery if someone have similar problem.
Part for adding header values:
$soap = new SoapClient($wsdl, $options);
$auth = array(
'userName' => self::SOAP_USERNAME,
'password' => self::SOAP_PASSWORD,
);
$header = new SoapHeader(self::SOAP_NAMESPACE, 'SecurityContext', $auth);
$soap->__setSoapHeaders($header);
Also, because it's https request I needed to add some ssl options:
// set stream context opts
$opts = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
// set options
$options = array(
'encoding' => 'UTF-8',
'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE,
'connection_timeout' => 15,
'login' => self::SOAP_USERNAME,
'password' => self::SOAP_PASSWORD,
'stream_context' => stream_context_create($opts),
);
i try to create orders with CreateOrder method in soap web service:
http://80.72.84.109/MW/services/bilkiservice.asmx?wsdl
with this simple code:
$soap = new SoapClient(MW_SOAP_URL, array(
"trace" => 1,
"exceptions" => 1
));
//set headers
$headerbody = array(
'Database' => MW_DATABASE,
'Username' => MW_USERNAME,
'Password' => MW_PASSWORD
);
$ns = 'http://tempuri.org/';
$header = new SoapHeader($ns, 'AuthenticationHeader', $headerbody);
$this->soap->__setSoapHeaders($header);
$orderInfo = array(
'OrderNumber' => 23344,
'Email' => 'test#test.com',
'Delivery' => array(
'Name' => 'Peter',
'City' => 'LA',
'Post' => 1000,
'Address' => 'Test Street 1',
'Email' => 'test#test.com',
'Phone' => '12345'
),
'PaymentType' => 2,
'Items' => array(
'OrderItem' => array(
'Code' => 3479,
'Quantity' => 1,
'TotalPrice' => 2.73
)
)
);
$soap->CreateOrder($orderInfo);
But i always get this error:
object(stdClass)#5 (1) { ["CreateOrderResult"]=> object(stdClass)#6 (4)
{ ["ErrorMessage"]=> string(53) "Object reference not set to an instance of an object."
["ErrorCode"]=> int(-1) ["Errs"]=> object(stdClass)#7 (0) { } ["OrderID"]=> int(0) } }
I successfully create new contragent with the other method CreateContragent, but CreateOrder didn't work.
May be the array data is wrong? But I tried many configurations and nothing works.
it is not your fault, your web-services didn't work. that is your CreatingOrder function's result description :
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CreateOrderResponse xmlns="http://tempuri.org/">
<CreateOrderResult>
<Errs>
<ErrorItem>
<ErrorCode>int</ErrorCode>
<ErrorMessage>string</ErrorMessage>
<ItemNumber>int</ItemNumber>
</ErrorItem>
<ErrorItem>
<ErrorCode>int</ErrorCode>
<ErrorMessage>string</ErrorMessage>
<ItemNumber>int</ItemNumber>
</ErrorItem>
</Errs>
<OrderID>int</OrderID>
</CreateOrderResult>
</CreateOrderResponse>
</soap:Body>
</soap:Envelope>
I want to send the below object using soap with php SoapClient.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:adin="http://3e.pl/ADInterface">
<soapenv:Header/>
<soapenv:Body>
<adin:queryData>
<adin:ModelCRUDRequest>
<adin:ModelCRUD>
<adin:serviceType>ReadSalesOrder</adin:serviceType>
<adin:TableName>XX_RV_Interface_Order</adin:TableName>
<adin:RecordID>0</adin:RecordID>
<adin:Filter></adin:Filter>
<adin:Action>Read</adin:Action>
<!--Optional:-->
<adin:DataRow>
<!--Zero or more repetitions:-->
<adin:field type="integer" column="C_BPartner_ID" lval="" disp="" edit="" error="" errorVal="">
<adin:val>1000643</adin:val>
</adin:field>
</adin:DataRow>
</adin:ModelCRUD>
<adin:ADLoginRequest>
<adin:user>username</adin:user>
<adin:pass>password</adin:pass>
<adin:lang>zh_CN</adin:lang>
<adin:ClientID>1000000</adin:ClientID>
<adin:RoleID>1000029</adin:RoleID>
<adin:OrgID>1000000</adin:OrgID>
<adin:WarehouseID>1000023</adin:WarehouseID>
</adin:ADLoginRequest>
</adin:ModelCRUDRequest>
</adin:queryData>
</soapenv:Body>
</soapenv:Envelope>
I have tried the below:
$wsdl = 'http://example.com/ModelADService?wsdl';
$client = new SoapClient($wsdl);
$result = $client->__soapCall('queryData', array(
'ModelCRUDRequest' => array(
'ModelCRUD' => array(
'serviceType' => 'ReadSalesOrder',
'TableName' => 'XX_RV_Interface_Order',
'RecordID' => 0,
'Filter' => '',
'Action' => 'Read',
'DataRow' => array(
'field' => array(
'type' => 'integer',
'column' => 'C_BPartner_ID',
'lval' => '',
'disp' => '',
'edit' => '',
'error' => '',
'errorVal' => '',
'val' => 1000643,
)
)
),
'ADLoginRequest' => array(
'user' => 'username',
'pass' => 'password',
'lang' => 'zh_CN',
'ClientID' => 1000000,
'RoleID' => 1000029,
'OrgID' => 1000000,
'WarehouseID' => 1000023,
'stage' => '',
),
),
));
var_dump($result);
Fatal error: Uncaught SoapFault exception: [soap:Client] Parameter ModelCRUDRequest does not exist!
SOAP Client must be initialized before
$client = new SoapClient($wsdl);
You're problem isn't with the soap call, but with the data you're sending or the receiving soap. soap is frustrating because you're calling a function on another server, and any errors thrown on that server trigger on your server. So if their function has a fatal error, your code will have a fatal error. This is why all soap calls must be inside a try catch.