简体   繁体   English

PHP Soap-无法连接到主机

[英]PHP Soap - Could not connect to host

I have looked at other solutions for this but can't find a similar issue: 我已经查看了其他解决方案,但是找不到类似的问题:

This bit of code works ok: 这段代码可以正常工作:

$wsdlUrl = "https://pilot.prove-uru.co.uk/URUws/uru10a.asmx?wsdl";
$client = new soapclient($wsdlUrl);
print_r($client->__getFunctions());

However when I try to make a method call: 但是,当我尝试进行方法调用时:

$params = array("AddressLookupUK" => array("address" => array("Postcode" => "NE20 9RF"),
            'AccountName' => "xxxx",
            'Password' => "xxxx"));
$result = $client->AddressLookupUK($params);

I get the error message "SoapFault exception: [HTTP] Could not connect to host". 我收到错误消息“ SoapFault异常:[HTTP]无法连接到主机”。 If I change the method call to 如果我将方法调用更改为

$result = $client->FalseMethod($params);

I get back "Function ("FalseMethod") is not a valid method for this service" which shows it is connecting as expected. 我回来了“函数(“ FalseMethod”)不是该服务的有效方法”,它表明它正在按预期方式连接。 Does anybody have any pointers I can try? 有人有我可以尝试的指针吗?

Thanks 谢谢

Here is the code I used, hope it helps someone: 这是我使用的代码,希望对您有所帮助:

$wsdlUrl = "address.wsdl";  


$client = new soapclient($wsdlUrl);
$params = array('address' => array('Postcode' => $postcode, 'BuildingNo' => $buildingNo),
                'AccountName' => 'XXXX',
                'Password' => 'XXXX');              
$result = $client->AddressLookupUK($params);
$echoText = '';
if (is_null($result->AddressLookupUKResult))
{
    //tell the user nothing was returned
}
else
{
    //checks to see if the result set contains only one item
    if (is_array($result->AddressLookupUKResult->URUAddressFixed))
    {
        foreach($result->AddressLookupUKResult->URUAddressFixed as $item)
        {
            //use code like $item->BuildingNo to access the data
        }
    }
    else
    {
        //if there was there was more than one then access using something like
        $result->AddressLookupUKResult->URUAddressFixed->BuildingNo
    }
}

Richard 理查德

At the WSDL you see the endpoint deinition: 在WSDL上,您可以看到端点定义:

<wsdl:service name="URU10a">
    <wsdl:port name="URU10aSoap" binding="tns:URU10aSoap">
        <soap:address location="https://pilot.prove-uru.co.uk:8443/URUws/uru10a.asmx"/>
    </wsdl:port>
    <wsdl:port name="URU10aSoap12" binding="tns:URU10aSoap12">
        <soap12:address location="https://pilot.prove-uru.co.uk:8443/URUws/uru10a.asmx"/>
    </wsdl:port>
</wsdl:service>

I think, you have problems connecting the 8443 port. 我认为,您在连接8443端口时遇到问题。 In my restricted network, the service works neither. 在我的受限网络中,该服务均无效。

EDIT 编辑

Ok, I tried to connect using the standard SSL port by changing the WSDL. 好的,我尝试通过更改WSDL使用标准SSL端口进行连接。 I have saved the WSDL from https://pilot.prove-uru.co.uk/URUws/uru10a.asmx?wsdl to my hard drive, removed the port numbers from the endpoint definitions and tried to connect using soapUI. 我已经将WSDL从https://pilot.prove-uru.co.uk/URUws/uru10a.asmx?wsdl保存到我的硬盘中,从端点定义中删除了端口号,并尝试使用soapUI进行连接。 Hooray, I got a response. 万岁,我得到了回应。

So maybe they moved the service from 8443 to 443 w/o updating the WSDL. 因此,也许他们不通过更新WSDL将服务从8443移至443。 Or it runs under both ports but you (and me) cannot connect the 8443 because of limitations of our local networks. 或者它在两个端口下运行,但是由于我们本地网络的限制,您(和我)无法连接8443。 Anyway I think you should contact the provider of this service and clarify this point instead of using a patched version of their WSDL. 无论如何,我认为您应该联系该服务的提供者并澄清这一点,而不要使用其WSDL的修补版本。

The "Function ("FalseMethod") is not a valid method for this service" error is only due to the WSDL check. 仅由于WSDL检查,“功能(“ FalseMethod”)不是此服务的有效方法”错误。 PHP successfully downloaded the WSDL, but can't access the Webservices in it. PHP已成功下载WSDL,但无法访问其中的Web服务。

You have to debug the Soap Call with trace set to 1: 您必须调试trace设置为1的Soap Call:

$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
echo "REQUEST HEADERS:\n" . $client->__getLastRequestHeaders() . "\n";
echo "RESPONSE HEADERS:\n" . $client->__getLastResponseHeaders() . "\n";
echo "Response:\n" . $client->__getLastResponse() . "\n";

Also, have a look at the URL's sets in the Wsdl. 另外,请查看Wsdl中的URL集。

I accepted DerVO's answer as his pointers helped me resolve the issue. 我接受了DerVO的回答,因为他的指针帮助我解决了该问题。 The port number was not totally causing the issue but I feel may have been contributing to it in some way. 端口号并非完全引起问题,但我认为可能是由于某种原因造成的。

When loading the WSDL in soap UI it was displaying the simple and complex object types without issue, but within PHP this caused it to fall over ie the WSDL defined a set of " 在soap UI中加载WSDL时,它显示的是简单和复杂的对象类型,没有问题,但是在PHP中,这导致它掉落,即WSDL定义了一组“

Richard 理查德

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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