Я искал несколько дней для решения этого, но не повезло.
Я получил код стартера от http://www.codingfriends.com/index.php/2010/04/16/soap-client-calling-net-web-service/ .
Вот код, скорректированный (с поддельным ключом):
<?php // create a connection to the local host mono .NET pull back the wsdl to get the functions names // and also the parameters and return values $client = new SoapClient("https://realServer/events.asmx?WSDL", array( "trace" => 1, // enable trace to view what is happening "exceptions" => 0, // disable exceptions "cache_wsdl" => 0) // disable any caching on the wsdl, encase you alter the wsdl server ); // get a response from the WSDL zend server function getQuote for the day monday print_r( $client->GetSingleEvent(array("APIKey" => "HISY20Y4-8405-91SK-L0S7-9A17252E548A", "EventId" => "2559"))); // display what was sent to the server (the request) echo "<p>Request :".htmlspecialchars($client->__getLastRequest()) ."</p>"; // display the response from the server echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>"; ?>
Вот как должен выглядеть фактический запрос xml (как проверено в пользовательском интерфейсе Soap)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:cer="http://cermsystem.net/"> <soapenv:Header> <tem:Credentials> <!--Optional:--> <tem:APIKey>HISY20Y4-8405-91SK-L0S7-9A17252E548A</tem:APIKey></tem:Credentials> </soapenv:Header> <soapenv:Body> <tem:GetSingleEvent> <!--Optional:--> <cer:GetEventByIDRQ> <!--Optional:--> <cer:EventId>2559</cer:EventId></cer:GetEventByIDRQ> </tem:GetSingleEvent> </soapenv:Body> </soapenv:Envelope>
Это текущий вывод, который я получаю из скрипта после отправки на .NET SOAP-сервер:
SoapFault Object ( [message:protected] => Server was unable to process request. ---> Object reference not set to an instance of an object. [string:Exception:private] => [code:protected] => 0 [file:protected] => /Library/WebServer/Documents/soap6.php [line:protected] => 15 [trace:Exception:private] => Array ( [0] => Array ( [file] => /Library/WebServer/Documents/soap6.php [line] => 15 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => GetSingleEvent [1] => Array ( [0] => Array ( [APIKey] => 8F0A395B-8405-480B-871C-9A17252E548A ) ) ) ) [1] => Array ( [file] => /Library/WebServer/Documents/soap6.php [line] => 15 [function] => GetSingleEvent [class] => SoapClient [type] => -> [args] => Array ( [0] => Array ( [APIKey] => 8F0A395B-8405-480B-871C-9A17252E548A ) ) ) ) [previous:Exception:private] => [faultstring] => Server was unable to process request. ---> Object reference not set to an instance of an object. [faultcode] => soap:Server [detail] => ) Request :<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"> <SOAP-ENV:Body> <ns1:GetSingleEvent/> </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:Server</faultcode> <faultstring>Server was unable to process request. ---> Object reference not set to an instance of an object.</faultstring> <detail /> </soap:Fault> </soap:Body> </soap:Envelope>
Я думаю, проблема в том, что сервер .NET не получает правильные входы для APIKey и EventId, но я не смог заставить эту часть работать. Должен ли APIKey быть отправлен как часть заголовка? Если да, то как мне это сделать в сочетании с чтением WSDL