我大多是 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"
}