PHP SoapClient调用.net -无法连接到主机


PHP SoapClient calling .NET - Could not connect to host

我有一个问题连接到。net web服务和WCF从PHP。当我从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上的本地Apache服务器调用服务,使用相同的php代码和一个简单的。net客户端-两者都运行在不同的网络上,而不是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,现在它可以工作了。