我在使用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}
我能够在我的Mac上使用相同的PHP代码和简单的.NET客户端从我当地的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。
答案 0 :(得分:0)
我终于明白了。我怀疑这是与GoDaddy相关的问题。他们只支持为80,443等几个端口发送数据。
所以我将用于服务的端口更改为端口80,现在它正在工作。