私は SOAP にほとんど慣れていないので、顧客のサーバーに接続するための小さなテスト スクリプトを作成しました。そこには、入力や認証を必要とせず、接続をテストするためだけの GetMessage コマンドがあります。
<?php
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$url = "https://test.mycustomer.com/api/TestService.svc?wsdl";
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
$result = $client->GetMessage(NULL);
echo "<pre>".print_r($result, true)."</pre>";
if($result->GetMessageResult->Status == "Success")
{
echo "Item deleted!";
}
?>
コマンドラインでこれを実行すると、次のようになります。
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /var/www/my.stage.com/htdocs/common/soaptest.php:8
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://459265-d...', 'http://tempuri....', 1, 0)
#1 [internal function]: SoapClient->__call('GetMessage', Array)
#2 /var/www/my.stage.com/htdocs/common/soaptest.php(8): SoapClient->GetMessage(NULL)
#3 {main}
thrown in /var/www/my.stage.com/htdocs/common/soaptest.php on line 8
そしてブラウザから私は得る:
PHP Notice: 'SoapClient::__doRequest() [soapclient.--dorequest]: php_network_getaddresses: getaddrinfo failed: Name or service not known'
このサービスの WSDL では、文字列「459265」が次のように表示されます。
<wsdl:service name="TestService">
<wsdl:port name="BasicHttpBinding_ITestService" binding="tns:BasicHttpBinding_ITestService">
<soap:address location="http://459265-dev1/api/TestService.svc"/>
</wsdl:port>
<wsdl:port name="BasicHttpsBinding_ITestService" binding="tns:BasicHttpsBinding_ITestService">
<soap:address location="https://test.mycustomer.com/api/TestService.svc"/>
</wsdl:port>
</wsdl:service>
だから私の質問は、それは正しいですか?WSDL には、自分のボックスからはアクセスできない、そのようなローカル URL が含まれている必要がありますか?
__getFunctions と __getTypes で var_dump を実行すると、もう少し情報が得られます。
array(2) {
[0]=>
string(53) "GetMessageResponse GetMessage(GetMessage $parameters)"
[1]=>
string(53) "GetMessageResponse GetMessage(GetMessage $parameters)"
}
array(5) {
[0]=>
string(21) "struct GetMessage {
}"
[1]=>
string(55) "struct GetMessageResponse {
string GetMessageResult;
}"
[2]=>
string(8) "int char"
[3]=>
string(17) "duration duration"
[4]=>
string(11) "string guid"
}