简体   繁体   中英

Consuming Microsoft .NET SOAP server datasets in PHP

I've read every question on Stackoverflow as well as every Google article I could find.

I need to consume a SOAP API that is being provided by a Microsoft system that uses datasets.

I've got to the point where I feel that I need to do this:

$soapClient = new soapclient($this->wsdlUrl,array('trace'=>true));
$soapResult = $soapClient->GetScheduledSectors();
$xmlResult = $soapClient->__getLastResponse();
$xml = simplexml_load_string($xmlResult, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");

Rather than using this approach:

$result = $soapClient->GetScheduledSectors();
$xml = simplexml_load_string($result->GetScheduledSectorsResult->any)

Because simplexml cannot parse the result as it lacks the soap response headers.

However, even though the first method does not throw any errors I am left with an empty object like this:

SimpleXMLElement Object
(
    [Body] => SimpleXMLElement Object
        (
        )
)

I really cannot find any coherent example of how to consume a Microsoft SOAP service. I tried reading the MSDN stuff but it's geared exclusively towards their proprietary libraries so is of little use to anybody else.

After trying nusoap I still hit my head against the wall. I eventually decided to manually parse the Microsoft XML.

Luckily there is a script ( here ) that saved me the hassle of doing this from scratch.

The script works and output the Microsoft dataset response into an array that I can use.

I feel quite bad with this solution because accessing the array is going to be done in a hard-coded way, but frankly after the amount of effort I have put into trying to find alternate solutions I see this as a necessary evil.

There are a few tools I resort to when running into SOAP issues,

  1. SoapUI It's a great tool that reads the service definition from the WSDL and creates stubbed out signatures for you. You can test hitting the service quickly and check responses & sample payloads when running into issues with your own clients.

  2. TCPMon When the going get's tough sometimes you have to look at the data going across the wire. Running a request (that works) through SoapUI, then the same payload through a SoapClient PHP program and watching them both in transit can help you isolate issues in the PHP code.

  3. NuSoap When all else fails... NuSoap was pre-SoapClient, but even after SoapClient hit the scenes NuSoap remains useful for edge cases where SoapClient just isn't cutting it. There are also some functions (eg. Soap Attachements?) NuSoap implements that SoapClient doesn't have.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM