I am connecting to a SOAP web service from a web application written in PHP, and I'm having issues getting the service to accept the objects I am attempting to send it. But only sometimes, and I can't figure out why particular objects are successfully passed while others are not.
I'm using PHP's SoapClient class, and if I use the __getFunctions() and __getTypes() methods, I get the following response: (For brevity's sake I will not list every single method and type)
This is the postOrder method I want to use within the webservice:
string(323) "respOrder postOrder(string $siteId, string $secretKey, string $language, string $customerName, string $emailAddress, parmAddress $deliveryAddress, parmAddress $billingAddress, parmCreditCard $creditCard, string $cvv, parmOrderLineArray $orderLines, string $shippingCharge, string $reference, string $poNumber, string $text)"
And here is an example of the object that is giving me trouble, parmAddress:
[1]=>
string(176) "struct parmAddress {
string addressLine1;
string addressLine2;
string addressLine3;
string city;
string countryCode;
string name;
string postalCode;
string stateCode;
}
I have attempted to construct this particular object in a number of different ways. Using the PHP stdObject, creating an object of a PHP class named parmAddress, and even sending an array. Unfortunately, the response I get from the web service is always the following. In this example I am just passing an object of one of the types I define below:
//The type of object I send
class parmAddress{
public $addressLine1 = '891 Prairie Grass Drive';
public $addressLine2 = '';
public $addressLine3 = '';
public $city = 'Las Vegas';
public $countryCode = '1';
public $name = 'Eric Dodson';
public $postalCode = '89123';
public $stateCode = 'NV';
}
//Or I've tried the stdObject as mentioned above
$obj = new stdClass();
$obj->addressLine1= '';
$obj->addressLine2= '';
$obj->addressLine3 = '';
$obj->city = 'Las Vegas';
$obj->countryCode = '1';
$obj->name = 'Eric Dodson';
$obj->postalCode = '89123';
$obj->stateCode = 'NV';
//Making the object and using the postOrder() method
$parmaddress = new parmAddress();
$order = $client->postOrder('user', 'pass', 'en', 'Eric Dodson', 'dodson@dodson.com', $parmaddress, $parmaddress, $parmcreditcard, '123', $parmorderlinearray, 0.00, 'No Comments');
//The response given to me by the webservice
object(stdClass)#6 (3) {
["code"]=>
string(7) "failure"
["message"]=>
string(21) "Invalid address name."
["orderNumber"]=>
int(0)
}
Oddly enough, I have had success sending other objects in what seems to be exactly the same way. For example, if I create the parmPart object in an identical fashion, and pass it with this getParts() method in the parmPartArray it asks for, it is successful.
$obj = new stdClass();
$obj->availabilityCode = '';
$obj->availableQuantity = '';
$obj->listPrice = '';
$obj->manufacturerCode = 'RPL';
$obj->partNumber = '341241';
$obj->price = '';
$obj->substitute = '';
$partsarray = array(
0 => $obj
);
$partsresponsearray = $client->getParts('user', 'pass', 'en', $partsarray);
I'm think it is important to note the web service wants to be sent structs which I am fairly unfamiliar with, and I'm hoping my problem will lie therein. The developer of the web service was able to tell me the following, but I haven't been able to find any additional information on sending objects from PHP to a web service that wants structs:
"That message is issued when the address name attribute is not filled. I remember for composite type like this parmAddress you have to "encode" it in PHP. I am not sure about the syntax now."
So apparently the web service thinks my "name" string is empty, and there is some type of encoding I must do to make it recognize what I am sending it. Any ideas? Thank you, I really appreciate the help!
As requested by another user, here is the WSDL:
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net.
RI's version is JAX-WS RI 2.1.7-b01-. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net.
RI's version is JAX-WS RI 2.1.7-b01-. -->
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://ws.reliableparts.net/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.reliableparts.net/"
name="RetailOrderServerService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.reliableparts.net/"
schemaLocation="http://www.reliableparts.net/dataservicetc/retail?xsd=1" />
</xsd:schema>
</types>
<message name="getParts">
<part name="siteId" type="xsd:string" />
<part name="secretKey" type="xsd:string" />
<part name="language" type="xsd:string" />
<part name="parts" type="tns:parmPartArray" />
</message>
<message name="getPartsResponse">
<part name="return" type="tns:parmPartArray" />
</message>
<message name="postOrder">
<part name="siteId" type="xsd:string" />
<part name="secretKey" type="xsd:string" />
<part name="language" type="xsd:string" />
<part name="customerName" type="xsd:string" />
<part name="emailAddress" type="xsd:string" />
<part name="deliveryAddress" type="tns:parmAddress" />
<part name="billingAddress" type="tns:parmAddress" />
<part name="creditCard" type="tns:parmCreditCard" />
<part name="cvv" type="xsd:string" />
<part name="orderLines" type="tns:parmOrderLineArray" />
<part name="shippingCharge" type="xsd:string" />
<part name="reference" type="xsd:string" />
<part name="poNumber" type="xsd:string" />
<part name="text" type="xsd:string" />
</message>
<message name="postOrderResponse">
<part name="return" type="tns:respOrder" />
</message>
<portType name="RetailOrderServer">
<operation name="getParts" parameterOrder="siteId secretKey language parts">
<input message="tns:getParts" />
<output message="tns:getPartsResponse" />
</operation>
<operation name="postOrder"
parameterOrder="siteId secretKey language customerName emailAddress deliveryAddress billingAddress creditCard cvv orderLines shippingCharge reference poNumber text">
<input message="tns:postOrder" />
<output message="tns:postOrderResponse" />
</operation>
</portType>
<binding name="RetailOrderServerPortBinding" type="tns:RetailOrderServer">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="rpc" />
<operation name="getParts">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" namespace="http://ws.reliableparts.net/" />
</input>
<output>
<soap:body use="literal" namespace="http://ws.reliableparts.net/" />
</output>
</operation>
<operation name="postOrder">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" namespace="http://ws.reliableparts.net/" />
</input>
<output>
<soap:body use="literal" namespace="http://ws.reliableparts.net/" />
</output>
</operation>
</binding>
<service name="RetailOrderServerService">
<port name="RetailOrderServerPort" binding="tns:RetailOrderServerPortBinding">
<soap:address location="http://www.reliableparts.net/dataservicetc/retail" />
</port>
</service>
</definitions>
Here are the results of using $client->__getLastRequest()
xmlns:ns1="http://ws.reliableparts.net/">
<SOAP-ENV:Body>
<ns1:postOrder>
<siteId>REDACTED</siteId>
<secretKey>REDACTED</secretKey>
<language>en</language>
<customerName>Eric Dodson</customerName>
<emailAddress>dodson@dodson.com</emailAddress>
<deliveryAddress id="ref1">
<addressLine1>891 Prairie Grass Drive</addressLine1>
<addressLine2 />
<addressLine3 />
<city>Las Vegas</city>
<countryCode>1</countryCode>
<name>Eric Dodson</name>
<postalCode>89123</postalCode>
<stateCode>NV</stateCode>
</deliveryAddress>
<deliveryAddress href="#ref1" />
<creditCard>
<expirationDate>201605</expirationDate>
<number>4111111111111111</number>
<type>Visa</type>
</creditCard>
<cvv>123</cvv>
<orderLines>
<item>
<manufacturerCode>RPL</manufacturerCode>
<partNumber>341241</partNumber>
<price>$99.99</price>
<quantity>1</quantity>
<text>No Comments</text>
</item>
</orderLines>
<shippingCharge>0</shippingCharge>
<reference>string</reference>
<poNumber>string</poNumber>
<text>string</text>
</ns1:postOrder>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>