First up, I'm trying to send a soap request using PHP SOAP and the XML that the service accepts is as shown below.
<U_MemberReservedTransaction xmlns="http://tempuri.org/">
<UserID>string</UserID>
<password>string</password>
<memberReservedTransactionRequest>
<memberReservedTransactions>
<ReservedType>string</ReservedType>
<Firstname>string</Firstname>
<Surname>string</Surname>
<IcNew>string</IcNew>
</memberReservedTransactions>
<memberReservedTransactions>
<ReservedType>string</ReservedType>
<Firstname>string</Firstname>
<Surname>string</Surname>
<IcNew>string</IcNew>
</memberReservedTransactions>
</memberReservedTransactionRequest>
</U_MemberReservedTransaction>
Just to summarize what the service is expecting, the service is to receive an array of memberReservedTransactions. My SOAP request call looks like below currently.
$client->callService('U_MemberReservedTransaction', array(
'UserID'=>'test1',
'password'=>'password',
'memberReservedTransactionRequest' => array(
'memberReservedTransaction' => array (
array(
'ReservedType'=>'Renew',
'Firstname'=>'',
'Surname'=>'',
'IcNew'=>''
)
)
)
));
As for what i'm expecting in return is a multidimensional array but my concern now is getting my request accepted.
Note : I'm getting a 500 Internal Server Error
Please help :<
Related
I'm trying to use PHP to pass submitted form fields to a web service that will create a user record in our database. I know the web service is working because I have ColdFusion code that is able to successfully create a user account with submitted parameters from my local machine. However, I need to get this working in php since our site is built in Drupal (php). I also tried the wsclient (drupal module) but to no avail.
I came accross this post (How to make a PHP SOAP call using the SoapClient class) which is similar to what I'm trying to do, but I keep getting an error. Here is the code I'm working with. Also, I need to pass the security password to use the web service in order to use it.
class Create {
function Create($securityPassword)
{
$this->securityPassword = $securityPassword;
}
}
$client = new SoapClient("https://isgweb.entnet.org/iservices/Account.asmx?WSDL");
$create = new Create("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); //web service password
$params = array(
"Create" => $create,
"Prefix" => "Mr",
"FirstName" => "John",
"LastName" => "Doe",
);
//print_r($params);
$response = $client->__soapCall('Create', array($params));
var_dump($response);
Here is the error I'm getting:
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\wamp\www\sandbox\webservice2.php:23 Stack trace: #0 C:\wamp\www\sandbox\webservice2.php(23): SoapClient->__soapCall('Create', Array) #1 {main} thrown in C:\wamp\www\sandbox\webservice2.php on line 23
The method I'm trying to call is the "Create" method. You can see it exists in the wsdl url
I'd appreciate help in trying to successfully create a record using the web service via php.
This should allow it work.
XML
<Create xmlns="http://ibridge.isgsolutions.com/Account/">
<securityPassword>string</securityPassword>
<account>
<Id>string</Id>
<Status>string</Status>
<MemberType>string</MemberType>
<JoinDate>string</JoinDate>
<Prefix>string</Prefix>
<FirstName>string</FirstName>
<MiddleName>string</MiddleName>
<LastName>string</LastName>
<Suffix>string</Suffix>
<Designation>string</Designation>
<InformalName>string</InformalName>
<MajorKey>string</MajorKey>
<Title>string</Title>
<ExcludeFromDirectory>string</ExcludeFromDirectory>
<WebSite>string</WebSite>
<Company>string</Company>
<CompanyID>string</CompanyID>
<OrgCode>string</OrgCode>
<SourceCode>string</SourceCode>
<ExcludeFromMail>string</ExcludeFromMail>
<Category>string</Category>
<Gender>string</Gender>
<BirthDate>string</BirthDate>
<WorkPhone>string</WorkPhone>
<Fax>string</Fax>
<TollFree>string</TollFree>
<HomePhone>string</HomePhone>
<Email>string</Email>
<Chapter>string</Chapter>
<FunctionalTitle>string</FunctionalTitle>
<PaidThru>string</PaidThru>
<WebLogin>string</WebLogin>
<Password>string</Password>
<SecurityGroup>string</SecurityGroup>
<ExpirationDate>string</ExpirationDate>
<StaffUser>string</StaffUser>
<WebUser>string</WebUser>
<Demographics>
<Demographic>
<Id>string</Id>
<SequenceNumber>string</SequenceNumber>
<WindowName>string</WindowName>
<FieldName>string</FieldName>
<FieldValue>string</FieldValue>
<MultiInstance>string</MultiInstance>
</Demographic>
<Demographic>
<Id>string</Id>
<SequenceNumber>string</SequenceNumber>
<WindowName>string</WindowName>
<FieldName>string</FieldName>
<FieldValue>string</FieldValue>
<MultiInstance>string</MultiInstance>
</Demographic>
</Demographics>
</account>
</Create>
code
$client = new SoapClient("https://isgweb.entnet.org/iservices/Account.asmx?WSDL");
$params = [
"Create" => [
'securityPassword' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'account' => [
'Prefix' => 'Mr',
'FirstName' => 'John',
'LastName' => 'Doe'
]
]
];
$response = $client->__soapCall('Create', $params)->CreateResult;
var_dump($response);
I wrote very simple code to retrieve soap data:
$wsdl = 'https://...';
$client = new SoapClient($wsdl, ['trace' => true]);
$soap_parameters = [
'leveranciernaam' => 'xxx',
'leveranciersleutel' => 'yyy',
'brinnummer' => 'zzzz',
'schooljaar' => 2012
];
$response = $client->getLeerlingen($soap_parameters);
To my huge surprise, the return was different from the return i received while using a Java based GUI application.
Some fields in PHP SoapClient's response were consistently missing.
Just to make sure that things were not lost in translation to stdObjects, I used trace option to and extracted actual XMl from $client->__getLastResponse();
Still those fields were not there - very consistently over hundreds of records.
Windows Java based client's response:
<return>
<leerlingen>
<leerling>
<id>353226866</id>
<roepnaam>Evline</roepnaam>
...
<achternaam>Staalstra</achternaam>
<inschrijvingen>
<inschrijving>
<id>353226867</id>
<datumInschrijving>2007-08-20T00:00:00+02:00</datumInschrijving>
<schoolVanHerkomst>7138</schoolVanHerkomst>
<vervolgSchool>7138</vervolgSchool>
<onderwijsSoortBestemming>
<id>4085</id>
</onderwijsSoortBestemming>
</inschrijving>
</inschrijvingen>
</leerling>
...
</leerlingen>
<brins>
<brin>
<id>47187537</id>
<brinNummer>02YN02</brinNummer>
<schoolNaam>De Ambelt School V LZK</schoolNaam>
</brin>
...
</brins>
</return>
Response i get:
<return>
<leerlingen>
<leerling>
<id>353226866</id>
<roepnaam>Evline</roepnaam>
...
<achternaam>Staalstra</achternaam>
<inschrijvingen>
<inschrijving>
<id>353226867</id>
<datumInschrijving>2007-08-20T00:00:00+02:00</datumInschrijving>
<inschrijvingType>1766564</inschrijvingType>
</inschrijving>
</inschrijvingen>
</leerling>
...
</leerlingen>
</return>
PHP client does not get (or does not properly parse) any elements schoolVanHerkomst, vervolgSchool and onderwijsSoortBestemming in element inschrijving and it misses brins completely.
For brevity, I omitted other deeply nested elements that work just fine
Because expected results are dynamic, WDSL ( https://acceptatie.parnassys.net/bao/services/cxf/v1/generic?wsdl ) does not define ouput.
What is going on? It seems that PHP Soap client is less reliable than Java Soap clients
I have to make a SOAP-Request with PHP to the DHL Carrier Service to generate batch labels. Somehow, I can't understand how it works. I wrote this code:
<?php
require_once('lib/Zend/Soap/Client.php');
require_once('lib/Zend/Soap/Client/Common.php');
$client = new Zend_Soap_Client('http://test-intraship.dhl.com/ws/1_0/ISService/DE.wsdl',
array(
'soap_version'=>SOAP_1_1
,'encoding' => 'UTF-8'
,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE
,'location'=>'https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp'
)
);
$location = 'https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp';
$request = '
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cis="http://dhl.de/webservice/cisbase" xmlns:de="http://de.ws.intraship">
<soap:Header><cis:Authentification><cis:user>magento</cis:user><cis:signature>m1a2$!</cis:signature><cis:accountNumber>5000000000</cis:accountNumber><cis:type>0</cis:type></cis:Authentification>
</soap:Header>
<soap:Body><de:CreateShipmentDDRequest>
<cis:Version>
<cis:majorRelease>1</cis:majorRelease>
<cis:minorRelease>0</cis:minorRelease></cis:Version><ShipmentOrder><SequenceNumber>1</SequenceNumber><Shipment><ShipmentDetails><ProductCode>EPN</ProductCode><ShipmentDate>2012-10-03</ShipmentDate><DeclaredValueOfGoods>10.2</DeclaredValueOfGoods><DeclaredValueOfGoodsCurrency>EUR</DeclaredValueOfGoodsCurrency><cis:EKP>5000000000</cis:EKP><Attendance><cis:partnerID>01</cis:partnerID></Attendance><CustomerReference>Auftrag 12883884</CustomerReference><ShipmentItem><WeightInKG>12</WeightInKG><LengthInCM>1</LengthInCM><WidthInCM>1</WidthInCM><HeightInCM>10</HeightInCM><PackageType>PK</PackageType></ShipmentItem><Service><ShipmentServiceGroupIdent><ReturnReceipt>false</ReturnReceipt></ShipmentServiceGroupIdent></Service><Service><ShipmentServiceGroupIdent><Personally>false</Personally></ShipmentServiceGroupIdent></Service><Service><ServiceGroupDHLPaket><Multipack>False</Multipack></ServiceGroupDHLPaket></Service><BankData><cis:accountOwner>DHL.de</cis:accountOwner><cis:accountNumber>1234567891</cis:accountNumber><cis:bankCode>87050000</cis:bankCode><cis:bankName>Sparkasse Chemnitz</cis:bankName><cis:iban>DE34870500001234567891</cis:iban><cis:note>Notiz Bank</cis:note><cis:bic>CHEKDE81XXX</cis:bic></BankData></ShipmentDetails><Shipper><Company><cis:Person><cis:firstname></cis:firstname><cis:lastname>Deutsche Post IT BRIEF GmbH</cis:lastname></cis:Person></Company><Address><cis:streetName>Heinrich-Brüning-Str.</cis:streetName><cis:streetNumber>7</cis:streetNumber><cis:Zip><cis:germany>53113</cis:germany></cis:Zip><cis:city>Bonn</cis:city><cis:Origin><cis:countryISOCode>DE</cis:countryISOCode></cis:Origin></Address><Communication><cis:phone>3935644</cis:phone><cis:email>dhl#dhl.com</cis:email><cis:contactPerson>IT Systeme Marketing Vertrieb</cis:contactPerson></Communication></Shipper><Receiver><Company><cis:Company><cis:name1>DHL Vertriebs GmbH Co. OHG</cis:name1></cis:Company></Company><Address><cis:streetName>Neue Poststr.</cis:streetName><cis:streetNumber>1</cis:streetNumber><cis:Zip><cis:other>08496</cis:other></cis:Zip><cis:city>Neumark</cis:city><cis:Origin><cis:countryISOCode>DE</cis:countryISOCode></cis:Origin></Address><Communication><cis:phone>3935655</cis:phone><cis:email>dhl#dhl.com</cis:email><cis:contactPerson>CIS 1J4</cis:contactPerson></Communication></Receiver><ExportDocument><InvoiceType>proforma</InvoiceType><InvoiceDate>2012-10-03</InvoiceDate><InvoiceNumber>444444</InvoiceNumber><ExportType>1</ExportType><ExportTypeDescription>für Sonstiges</ExportTypeDescription><CommodityCode>8888888</CommodityCode><TermsOfTrade>CIP</TermsOfTrade><Amount>2000</Amount><Description>777777</Description><CountryCodeOrigin>DE</CountryCodeOrigin><AdditionalFee>3.12</AdditionalFee><CustomsValue>2.23</CustomsValue><CustomsCurrency>EUR</CustomsCurrency><PermitNumber>666666</PermitNumber><AttestationNumber>?</AttestationNumber><ExportDocPosition><Description>Harddisk</Description><CountryCodeOrigin>DE</CountryCodeOrigin><CommodityCode>123456</CommodityCode><Amount>200</Amount><NetWeightInKG>1</NetWeightInKG><GrossWeightInKG>1.2</GrossWeightInKG><CustomsValue>200</CustomsValue><CustomsCurrency>EUR</CustomsCurrency></ExportDocPosition></ExportDocument></Shipment><LabelResponseType>URL</LabelResponseType></ShipmentOrder></de:CreateShipmentDDRequest></soap:Body></soap:Envelope>
';
$clientCommon = new Zend_Soap_Client_Common($client, 'http://test-intraship.dhl.com/ws/1_0/ISService/DE.wsdl',
array(
'soap_version'=>SOAP_1_1
,'encoding' => 'UTF-8'
,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE
,'location'=>'https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp'
));
$response = $client->_doRequest($clientCommon, trim($request), $location, 'createShipmentDD', SOAP_1_1);
print_r($response);
?>
The XML code is copied from the DHL test tool, the access data are standard test data, which should actually always work. But I always become a "Wrong login data"-message. Why can it be?
I tried to find something out with the SoapUI programm but I don't seem to understand how all this stuff work.
Can you please give me some help?
The URL you are trying sending your SOAP-Request to (https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp) is not used as an Web Service endpoint - it is the Single-Sign-On URL for logging in your customer to the DHL Intraship Customer Portal (you can submit parceldata manually there).
The endpoint for the Web Service is http://test-intraship.dhl.com/ws/1_0/de/ISService (Source: https://entwickler.dhl.de/group/ep/webservices/intraship/quick-start)
You may need more information from DHL
https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp
To Login this URL you need User name and password, This information is other than cis:Authentification section you passed in soap:Header node.
This new User name and password you need to set in new "Zend_Soap_Client_Common" object.
ClickandBuy provides lots of samples, but they are poorly coded and old. So I think there should be an easy PHP 5 SOAP solution for a simple SOAP payRequest with the PHP5 build in SoapClient class.
$client = new SoapClient('https://api.clickandbuy.com/webservices/pay_1_1_0.wsdl', array('encoding' => 'UTF-8'));
$client->payRequest(array('authentication'=>array(...), 'details'=>array(...)));
Works, but it returns an error:
SOAP-ERROR: Encoding: object has no 'description' property
The arguments of the payRequest method should be fine. Did anyone try to implement ClickandBuy without NuSOAP?
Try adding description property into details array:
$client->payRequest(array('authentication'=>array(...),
'details' => array(
'description' => 'paying for shoes'
)
));
Sample request:
<?xml version="1.0" encoding="UTF-8"?>
<payRequest_Request xmlns="http://api.clickandbuy.com/webservices/pay_1_1_0/">
<authentication>
<merchantID>4000</merchantID>
<projectID>1</projectID>
<token>20100623104511::9E9C3E21FE38851B8913469F13619BD645BA1DD6</token>
</authentication>
<details>
<amount>
<amount>1</amount>
<currency>EUR</currency>
</amount>
<orderDetails>
<text>My Cart</text>
</orderDetails>
<successURL>http://www.mydomain.com/success.php</successURL>
<failureURL>http://www.mydomain.com/failure.php</failureURL>
<externalID>Test123</externalID>
</details>
</payRequest_Request>
I am trying to make a web service call from PHP to a SOAP web service with a sample request which looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.somedomain.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:SearchMarketplaceSku>
<ws:Request>
<ws:Security>
<ws:PartnerKey>[suppressed]</ws:PartnerKey>
<ws:Password>[suppressed]</ws:Password>
</ws:Security>
<ws:AvailableOnDate>2012-04-03T00:00:00</ws:AvailableOnDate>
<ws:IncludeStateDetails>true</ws:IncludeStateDetails>
<ws:State>CA</ws:State>
</ws:Request>
</ws:SearchMarketplaceSku>
</soapenv:Body>
</soapenv:Envelope>
The PHP code being used is:
$soapClient = new SoapClient($wsdlUrl);
$ap_param = array('PartnerKey' => $PartnerKey, 'Password' => $metapackPassword, 'AvailableOnDate' => '2012-04-03T00:00:00','IncludeStateDetails'=>true, 'State'=>'CA');
$info = $soapClient->__call("SearchMarketplaceSku", $ap_param);
The web service call results in an "Request was not specified properly; server unable to deserialize request" error? What is the problem? Does the $ap_param array need to include all the nested nodes coressponding with the XML? Is there an easier way to make this call using "WSDL" mode?
Thanks for your help
PartnerKey and Password has to be in an Array under the key Security:
$ap_param = array(
'Security' => array(
'PartnerKey' => $PartnerKey,
'Password' => $metapackPassword
),
'AvailableOnDate' => '2012-04-03T00:00:00',
'IncludeStateDetails'=>true, 'State'=>'CA'
);