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.
Related
I'm trying to consume a method, but it returns me that Login failed, but in SOAPUI it works normally.
I think the error is in the array I'm sending.
Is this my array compared to XML is correct?
XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="https://product.net" xmlns:trav="http://schemas.datacontract.org/2004/07/Product.Report" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<soapenv:Header/>
<soapenv:Body>
<int:Product>
<int:request>
<trav:Color>
<arr:int>3</arr:int>
<arr:int>5</arr:int>
</trav:Color>
<trav:Cod>1</trav:Cod>
<trav:Price>
<arr:string>1.50</arr:string>
<arr:string>9.00</arr:string>
</trav:Price>
<trav:Size>G</trav:Size>
</int:request>
<int:Login>
<trav:Pass>123456</trav:Pass>
<trav:User>user123</trav:User>
</int:Login>
</int:Product>
</soapenv:Body>
</soapenv:Envelope>
My array:
$consume->xmlArray = array(
"request" => array(
"Color" => array(
array(
"int" => '3'
),
array(
"int" => '5'
)
),
"Cod" => "1",
"Price" => array(
array(
"string" => "1.50"
),
array(
"string" => "9.00"
),
),
"Size" => "G"
),
"Login" => array(
"Pass" => "123456",
"User" => "user123"
)
);
Return:
Fatal error: Uncaught SoapFault exception: [s:Client] Login Failed. in /var/www/html/Consume.php:85
Function Class Cosume:
public function Product(){
$client = new SoapClient( $this->wsdl_url, array( "trace" => 1 ) );
$params = $this->xmlArray;
$response = $client->Product($params);
return $response;
}
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 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);
I have a php nusoap service defined as below:
$server->wsdl->addComplexType(
'OrderType',
'complexType',
'struct',
'all',
'',
array(
'OrderId' => array('name' => 'OrderId', 'type' => 'xsd:string'),
'CustomerNumber' => array('name' => 'CustomerNumber', 'type' => 'xsd:string'),
)
);
$server->register("testService",
array("OrderData" => "tns:OrderType"),
array("return" => "tns:OrderType"), //array("return" => "xsd:string"),
"urn:aaa",
"urn:aaa#testService",
"rpc",
"encoded",
"");
If I pass in the envelope as below:
<soapenv:Body>
<sch:Request xmlns:sch="http://aaa.com//Schema.xsd">
<sch:OrderId>OA1236</sch:OrderId>
<sch:CustomerNumber>PIN555</sch:CustomerNumber>
</sch:Request>
</soapenv:Body>
How do I process the parameter $OrderData? I'd expect it to work as below but this doesn't work
function testService($OrderData) {
$result['OrderId'] = $OrderData['OrderData'];
$result['CusomterNumber'] = $OrderData['CustomerNumber'];
return $result;
}
Try this code:
function testService($OrderData) {
$result['OrderId'] = $OrderData['OrderId']; // OrderId instead of OrderData
$result['CustomerNumber'] = $OrderData['CustomerNumber'];
return $result;
}
I'm having a problem with a soapclient call. The soaprequest has to look like:
<eng:Compose>
<!--Optional:-->
<EWSComposeRequest>
<!--Optional:-->
<driver>
<!--Optional:-->
<driver>base64</driver>
<!--Optional:-->
<fileName>INPUT</fileName>
</driver>
<engineOptions>
<name>FILEMAP</name>
<value>DLFOUT.dlf,dummy.dlf</value>
</engineOptions>
<engineOptions>
<name>FILEMAP</name>
<value>PDFOUT.pdf,dummy.pdf</value>
</engineOptions>
<engineOptions>
<name>RUNMODE</name>
<value>PRODUCTION</value>
</engineOptions>
<!--Optional:-->
<fileReturnRegEx>^.*.(dlf|pdf)$</fileReturnRegEx>
<includeHeader>True</includeHeader>
<includeMessageFile>True</includeMessageFile>
<!--Optional:-->
<pubFile>TestLive.pub</pubFile>
</EWSComposeRequest>
</eng:Compose>
My soap_param is:
$soap_param = array("Compose"=> array("EWSComposeRequest" =>
array( "driver" => array( "driver" => $post_Driver,
"fileName" => $post_FileName),
"engineOptions" => array( "name" => "KEY", "value" => $INI['encodedkey']),
"engineOptions" => array( "name" => "RUNMODE", "value" => $INI['runmode']),
"fileReturnRegEx" => $post_FileReturnRegEx, "includeHeader" => $post_IncludeHeader,
"includeMessageFile" => $post_IncludeMessage, "pubFile" => $post_PubFile)));
The soapcall appears to work, however.... I only reveive the last engineOptions element.
According to the xsd the element engineOptions can appear multiple times(0 to unbounded). Witin the soapcall this element seems to be overwritten. The index: engineOptions isn't unique.
I can't imagine that i am the only one facing this problem. I hope that there is a (simple) solution for this problem.
With special thanks to: András Szepesházi. The following $soap_param definition:
$soap_param => array(
'Compose' => array(
'EWSComposeRequest' => array(
'driver' => array(
'driver' => $post_Driver,
'fileName' => $post_FileName
),
'engineOptions' => array(
array(
'name' => 'KEY',
'value' => $INI['encodedkey']
),
array(
'name' => 'RUNMODE',
'value' => $INI['runmode']
),
array(
'name' => 'FILEMAP',
'value' => "DLFOUT.dlf,dummy.dlf"
),
array(
'name' => 'FILEMAP',
'value' => "PDFOUT.pdf,dummy.pdf"
),
),
'fileReturnRegEx' => $post_fileReturnPattern,
'includeHeader' => $post_IncludeHeader,
'includeMessageFile' => $post_IncludeMessage,
'pubFile' => $post_PubFile
)
)
);
Is able to create the following SOAP Request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:hpexstream-services/Engine">
<SOAP-ENV:Header>
<ns1:n>n</ns1:n>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:Compose>
<EWSComposeRequest>
<driver>
<driver>base64</driver>
<fileName>INPUT</fileName>
</driver>
<engineOptions>
<name>KEY</name>
<value>base64</value>
</engineOptions>
<engineOptions>
<name>RUNMODE</name>
<value>PRODUCTION</value>
</engineOptions>
<engineOptions>
<name>FILEMAP</name>
<value>DLFOUT.dlf,dummy.dlf</value>
</engineOptions>
<engineOptions>
<name>FILEMAP</name>
<value>PDFOUT.pdf,dummy.pdf</value>
</engineOptions>
<includeHeader>true</includeHeader>
<includeMessageFile>true</includeMessageFile>
<pubFile>TestLive.pub</pubFile>
</EWSComposeRequest>
</ns1:Compose>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So problem solved.