NYCPHP Meetup

NYPHP.org

[nycphp-talk] Consuming a .NET Web Service with PHP

Todd Sinagra tsinagra at gmail.com
Sat Nov 24 20:42:30 EST 2007


I am trying to consume a .NET Web Service for M/S Dynamics GP (which
used to be Great Plains) and I just can't seem to get it working. I
have contacted M/S Dynamics support about my problem and they tell me
PHP is not supported use C#. So if anyone could please help it would
be greatly appreciated.

 Every time I run this bit of code, trying to use the GetCustomerByKey method:

<?php
$options = array('login'	 => 'loginid',
    			'password'	 => 'pwd',
    			'trace'		 => TRUE,
				'exceptions' => TRUE);

$wsdl = 'http://nabacct01/DynamicsGPWebServices/DynamicsGPService.asmx?WSDL';

$client = new SoapClient ($wsdl, $options);

try
{
	$key = array('key' => array('Id' => 'ACETRAVEL'));
	$company_key = array('Id' => -1);
	$context = array('Context' => array('CurrencyType' => 'Local',
							            'OrganizationKey' => $company_key,
										'CultureName' => 'en-US'));

	$param = array_merge($key, $context);
	//echo "<pre>";print_r($param);echo "</pre><br>";//exit;
	echo "<pre>";print_r($key);echo "</pre><br>";//exit;
	echo "<pre>";print_r($context);echo "</pre><br>";//exit;
	echo "<pre>";print_r($param);echo "</pre><br>";//exit;

	$res = $client->GetCustomerByKey($param);
}
catch(SoapFault $soapFault)
{
	echo htmlentities($soapFault);
}

echo '<br>';
echo "<pre>";
echo "Request :<br>".htmlspecialchars($client->__getLastRequest()) ."<br>";
echo "</pre>";
echo "<pre>";
echo "Response:<br>".htmlspecialchars($client->__getLastResponse())."<br>";
echo "</pre>";

?>

I get this SoapFault exception:

SoapFault exception: [soap:Client] Server was unable to read request.
---> There is an error in XML document (2, 294). ---> The specified
type is abstract: name='OrganizationKey',
namespace='http://schemas.microsoft.com/dynamics/2006/01', at
<OrganizationKey
xmlns='http://schemas.microsoft.com/dynamics/2006/01'>. in
/home/enc/www/bancard/gp/simple.php:27 Stack trace: #0 [internal
function]: SoapClient->__call('GetCustomerByKe...', Array) #1
/home/enc/www/bancard/gp/simple.php(27):
SoapClient->GetCustomerByKey(Array) #2 {main}


Here are the SOAP request and response that I get when calling the Web
Server by outputting the __getLastRequest and __getLastResponse.
Request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://schemas.microsoft.com/dynamics/gp/2006/01"
xmlns:ns2="http://schemas.microsoft.com/dynamics/2006/01"><SOAP-ENV:Body><ns1:GetCustomerByKey><ns1:key><ns1:Id>ACETRAVEL</ns1:Id></ns1:key>
<ns2:Context><ns2:OrganizationKey/><ns2:CultureName>en-US</ns2:CultureName><ns2:CurrencyType>Local</ns2:CurrencyType></ns2:Context>
</ns1:GetCustomerByKey></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Server
was unable to read request. ---&gt; There is an error in XML document
(2, 294). ---&gt; The specified type is abstract:
name='OrganizationKey',
namespace='http://schemas.microsoft.com/dynamics/2006/01', at
&lt;OrganizationKey
xmlns='http://schemas.microsoft.com/dynamics/2006/01'&gt;.</faultstring><detail
/></soap:Fault></soap:Body></soap:Envelope>


Due to the size of the WSDL and other docs, information I have
included links to them below.

-- Dynamics GP WSDL
http://sinagra.org/gp/DynamicsGPService.WSDL

-- Dynamics Soap Response and Request
http://sinagra.org/gp/GetCustomerByKey.asmx.html

-- SoapClient->__getFunctions()
http://sinagra.org/gp/get_functions.php.html

-- SoapClient->__getTypes()
http://sinagra.org/gp/get_types.php.html


Thanks.

- Todd



More information about the talk mailing list