[英]PHP SoapClient calling .NET - Could not connect to host
我從PHP連接到.NET Web服務和WCF時遇到問題。 當我從GoDaddy托管服務器(Linux)運行PHP代碼時,收到以下錯誤:
SoapFault exception: [HTTP] Could not connect to host in /home/content/mydir/test.php:13 Stack trace: #0 [internal function]: SoapClient->__doRequest('__call('HelloWorld', Array) #2 /home/content/mydir/test.php(13): SoapClient->HelloWorld() #3 {main}
我能夠使用相同的PHP代碼和簡單的.NET客戶端從Mac上的本地Apache服務器成功調用該服務-兩者都在與Web服務不同的網絡上運行,因此我認為它不是綁定相關問題。
WSDL保存在本地的php服務器上。
我試圖將位置添加到PHP SoapClient。
過去一周我也在網上應用了許多其他建議,但很不幸。
我在這里使用的Web服務是生成的HelloWorld Web服務。
我的WSDL中的wsdl定義部分:
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://mydomain.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://mydomain.com/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://mydomain.com/">
<s:element name="HelloWorld">
<s:complextype />
</s:element>
<s:element name="HelloWorldResponse">
<s:complextype>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
</s:sequence>
</s:complextype>
</s:element>
<s:element name="string" nillable="true" type="s:string" />
</s:schema>
</wsdl:types>
<wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
</wsdl:message>
<wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
</wsdl:message>
<wsdl:message name="HelloWorldHttpGetIn" />
<wsdl:message name="HelloWorldHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="HelloWorldHttpPostIn" />
<wsdl:message name="HelloWorldHttpPostOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:porttype name="UploadServiceSoap">
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
</wsdl:operation>
</wsdl:porttype>
<wsdl:porttype name="UploadServiceHttpGet">
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldHttpGetIn" />
<wsdl:output message="tns:HelloWorldHttpGetOut" />
</wsdl:operation>
</wsdl:porttype>
<wsdl:porttype name="UploadServiceHttpPost">
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldHttpPostIn" />
<wsdl:output message="tns:HelloWorldHttpPostOut" />
</wsdl:operation>
</wsdl:porttype>
<wsdl:binding name="UploadServiceSoap" type="tns:UploadServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://mydomain.com/HelloWorld" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="UploadServiceSoap12" type="tns:UploadServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap12:operation soapAction="http://mydomain.com/HelloWorld" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="UploadServiceHttpGet" type="tns:UploadServiceHttpGet">
<http:binding verb="GET" />
<wsdl:operation name="HelloWorld">
<http:operation location="/HelloWorld" />
<wsdl:input>
<http:urlencoded />
</wsdl:input>
<wsdl:output>
<mime:mimexml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="UploadServiceHttpPost" type="tns:UploadServiceHttpPost">
<http:binding verb="POST" />
<wsdl:operation name="HelloWorld">
<http:operation location="/HelloWorld" />
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded" />
</wsdl:input>
<wsdl:output>
<mime:mimexml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="UploadService">
<wsdl:port name="UploadServiceSoap" binding="tns:UploadServiceSoap">
<soap:address location="http://my_external_IP:1234/UploadService.asmx" />
</wsdl:port>
<wsdl:port name="UploadServiceSoap12" binding="tns:UploadServiceSoap12">
<soap12:address location="http://my_external_IP:1234/UploadService.asmx" />
</wsdl:port>
<wsdl:port name="UploadServiceHttpGet" binding="tns:UploadServiceHttpGet">
<http:address location="http://my_external_IP:1234/UploadService.asmx" />
</wsdl:port>
<wsdl:port name="UploadServiceHttpPost" binding="tns:UploadServiceHttpPost">
<http:address location="http://my_external_IP:1234/UploadService.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
PHP代碼:
<?php
define('NEWLINE', '<br/>');
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$wsdl = 'wsdl/UploadService.wsdl';/* $wsdl = 'wsdl/UploadService.wsdl'; */
try {
$client = new SoapClient($wsdl, array('trace' => 1, 'exceptions' => true,'soap_version' => SOAP_1_2,'cache_wsdl' => 0, 'connection_timeout' => 600));
print_r($client);
echo NEWLINE;
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
echo NEWLINE;
$client->HelloWorld();
echo "HEADERS: ".$client->__getLastRequestHeaders().NEWLINE;
echo "RESPONSE: ".$client->__getLastResponse().NEWLINE;
echo "DONE";
die();
} catch(Exception $e) {
die($e);
}
?>
__getFunctions()和__getTypes()函數可在任何地方正常工作。
有沒有人有什么建議 ?
謝謝 ! :-)
Roei。
我終於弄明白了。 我懷疑這是與GoDaddy相關的問題。 他們僅支持將數據發送到一些端口,例如80、443 ...
因此,我將用於服務的端口更改為端口80,現在它可以正常工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.