Jump to content

[SOLVED] Problem consuming .NET web service in PHP, data not being mapped to variables


jasonok6

Recommended Posts

I work at a company where we develop in PHP as well as .NET.  I have written a simple web service in C# that I need to consume via PHP.  The problem is that no matter how I return the data from C# whether a multi dimensional array, an array of objects, a .NET datatable type etc... PHP maps ALL of the xml to a single variable.  I am trying to figure out how to get the different variables in the XML mapped to multiple variables into PHP which I can then traverse.  Within PHP we are currently consuming coldfusion as well as other php web services without any problems.  Seems that php doesn't like .NET for some reason. Here is the code I am using to generate the request using PHP 5.2:

<?php
function ws_consume($url,$parms,$action)
{
    $client = new SoapClient($url);
    return $client->__soapCall($action,$parms);
}
$ar['intPageNumber'] = 1; //not implemented yet on ws side
$ar['intRows'] = 10; //not implemented yet on ws side
$obj = ws_consume(STORE_WS,$ar,'CartUserReferences');
print_r($obj);
?>

Here is the result I am getting from php:

stdClass Object
(
    [CartUserReferencesResult] => stdClass Object
        (
            [any] => <CustomerRecord><user_id>15256</user_id><customer_id>7036be16-8ce0-4e7a-b55b-9fcacf820d82</customer_id></CustomerRecord><CustomerRecord><user_id>15255</user_id><customer_id>2c115556-0737-4443-9897-5c836c133dfb</customer_id></CustomerRecord><CustomerRecord><user_id>15250</user_id><customer_id>6f020f6b-f6be-49eb-ad1e-860a815ace04</customer_id></CustomerRecord><CustomerRecord><user_id>15247</user_id><customer_id>00a10a0e-7bfb-435b-8e36-a51a1fbfdc1b</customer_id></CustomerRecord><CustomerRecord><user_id>15246</user_id><customer_id>9edff925-924b-4695-82e6-4fcbd90c8060</customer_id></CustomerRecord><CustomerRecord><user_id>15245</user_id><customer_id>174eddc3-a62d-4e90-8578-b59afaca69be</customer_id></CustomerRecord><CustomerRecord><user_id>15243</user_id><customer_id>5f55dcd0-cd73-497c-bc62-a2ddb9d08e07</customer_id></CustomerRecord><CustomerRecord><user_id>15242</user_id><customer_id>6ae29b9f-544b-4b5e-b90a-b94523f3c76e</customer_id></CustomerRecord><CustomerRecord><user_id>15229</user_id><customer_id>8797aa8d-0bf9-4be3-a14c-8cebcf61802a</customer_id></CustomerRecord><CustomerRecord><user_id>15227</user_id><customer_id>7164f0f0-3c98-4b99-a113-ef229840f678</customer_id></CustomerRecord><CustomerRecord><user_id>15226</user_id><customer_id>3a5ac983-7d00-4e7d-add0-b4da5d9e0317</customer_id></CustomerRecord>

        )

)

 

Here is the raw xml returned by the .NET service:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfCustomerRecord xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
  <CustomerRecord>
    <user_id>15255</user_id>
    <customer_id>2c115556-0737-4443-9897-5c836c133dfb</customer_id>
  </CustomerRecord>
  <CustomerRecord>
    <user_id>15250</user_id>

    <customer_id>6f020f6b-f6be-49eb-ad1e-860a815ace04</customer_id>
  </CustomerRecord>
  <CustomerRecord>
    <user_id>15247</user_id>
    <customer_id>00a10a0e-7bfb-435b-8e36-a51a1fbfdc1b</customer_id>
  </CustomerRecord>
  <CustomerRecord>

    <user_id>15246</user_id>
    <customer_id>9edff925-924b-4695-82e6-4fcbd90c8060</customer_id>
  </CustomerRecord>
  <CustomerRecord>
    <user_id>15245</user_id>
    <customer_id>174eddc3-a62d-4e90-8578-b59afaca69be</customer_id>
  </CustomerRecord>

  <CustomerRecord>
    <user_id>15243</user_id>
    <customer_id>5f55dcd0-cd73-497c-bc62-a2ddb9d08e07</customer_id>
  </CustomerRecord>
  <CustomerRecord>
    <user_id>15242</user_id>
    <customer_id>6ae29b9f-544b-4b5e-b90a-b94523f3c76e</customer_id>

  </CustomerRecord>
  <CustomerRecord>
    <user_id>15229</user_id>
    <customer_id>8797aa8d-0bf9-4be3-a14c-8cebcf61802a</customer_id>
  </CustomerRecord>
  <CustomerRecord>
    <user_id>15227</user_id>

    <customer_id>7164f0f0-3c98-4b99-a113-ef229840f678</customer_id>
  </CustomerRecord>
  <CustomerRecord>
    <user_id>15226</user_id>
    <customer_id>3a5ac983-7d00-4e7d-add0-b4da5d9e0317</customer_id>
  </CustomerRecord>
</ArrayOfCustomerRecord>

 

Thanks in advance!

Having the ability to edit ones post would be awesome.  I accidentally pasted the wrong xml output in my original message it should have been this:

<?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><CartUserReferencesResponse xmlns="http://tempuri.org/"><CartUserReferencesResult><CustomerRecord><user_id>15256</user_id><customer_id>7036be16-8ce0-4e7a-b55b-9fcacf820d82</customer_id></CustomerRecord><CustomerRecord><user_id>15255</user_id><customer_id>2c115556-0737-4443-9897-5c836c133dfb</customer_id></CustomerRecord><CustomerRecord><user_id>15250</user_id><customer_id>6f020f6b-f6be-49eb-ad1e-860a815ace04</customer_id></CustomerRecord><CustomerRecord><user_id>15247</user_id><customer_id>00a10a0e-7bfb-435b-8e36-a51a1fbfdc1b</customer_id></CustomerRecord><CustomerRecord><user_id>15246</user_id><customer_id>9edff925-924b-4695-82e6-4fcbd90c8060</customer_id></CustomerRecord><CustomerRecord><user_id>15245</user_id><customer_id>174eddc3-a62d-4e90-8578-b59afaca69be</customer_id></CustomerRecord><CustomerRecord><user_id>15243</user_id><customer_id>5f55dcd0-cd73-497c-bc62-a2ddb9d08e07</customer_id></CustomerRecord><CustomerRecord><user_id>15242</user_id><customer_id>6ae29b9f-544b-4b5e-b90a-b94523f3c76e</customer_id></CustomerRecord><CustomerRecord><user_id>15229</user_id><customer_id>8797aa8d-0bf9-4be3-a14c-8cebcf61802a</customer_id></CustomerRecord><CustomerRecord><user_id>15227</user_id><customer_id>7164f0f0-3c98-4b99-a113-ef229840f678</customer_id></CustomerRecord><CustomerRecord><user_id>15226</user_id><customer_id>3a5ac983-7d00-4e7d-add0-b4da5d9e0317</customer_id></CustomerRecord></CartUserReferencesResult></CartUserReferencesResponse></soap:Body></soap:Envelope>

Solved my own problem.  My php.ini settings were caching WSDLs and i had originally tested the webservice returning back a single value.  Once I changed the web service so that it was returning complex data php was still using the rules from the old WSDL.  Turned off soap caching and it started working as expected.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.