【问题标题】:PHP - create and call SOAP web service - errorPHP - 创建和调用 SOAP Web 服务 - 错误
【发布时间】:2011-09-22 19:16:22
【问题描述】:

每次我尝试通过 wsdl 调用我的 web 服务时,都会收到此处显示的错误消息。我认为这可能是 WSDL 定义中的一个问题,因为我不确定我在 WSDL 定义中首先要做什么:

 [22-Sep-2011 18:54:46] PHP Fatal error:  Uncaught SoapFault exception:
 [HTTP] Not Found in /www/zendserver/htdocs/dev/csc/request.php:4
 Stack trace:
 #0 [internal function]: SoapClient->__doRequest('<?xml version="...',
 'http://192.168....', 'http://www.exam...', 1, 0)
 #1 [internal function]: SoapClient->__call('EchoText', Array)
 #2 /www/zendserver/htdocs/dev/csc/request.php(4):
 SoapClient->EchoText('test')
 #3 {main}   thrown in /www/zendserver/htdocs/dev/csc/request.php on
 line 4

我有一个非常简单的网络服务,位于: http://192.168.1.2:10088/csc/csc.php

<?php

function EchoText($text){
    return "ECHO: ".$text;
}

$server = new SoapServer(null,
                         array('uri' => "http://192.168.1.2:10088/csc/csc.php"));
$server->addFunction('EchoText');
$server->handle();

?>

我有一个接口页面,这是我访问的页面,然后得到上面显示的错误,位于: http://192.168.1.2:10088/csc/request.php

<?php
$client = new SoapClient("http://192.168.1.2:10088/csc/NewWSDLFile.wsdl");

$result = $client->EchoText("test");
echo $result;
>?

我有我的 WSDL,位于: http://192.168.1.2:10088/csc/NewWSDLFile.wsdl

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://192.168.1.2:10088/csc/NewWSDLFile.wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NewWSDLFile" targetNamespace="http://192.168.1.2:10088/csc/NewWSDLFile.wsdl">
  <wsdl:types>
    <xsd:schema targetNamespace="http://192.168.1.2:10088/csc/NewWSDLFile.wsdl">
      <xsd:element name="EchoText">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="in" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="EchoTextResponse">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="out" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="EchoTextRequest">
    <wsdl:part element="tns:EchoText" name="parameters"/>
  </wsdl:message>
  <wsdl:message name="EchoTextResponse">
    <wsdl:part element="tns:EchoText" name="parameters"/>
  </wsdl:message>
  <wsdl:portType name="NewWSDLFile">
    <wsdl:operation name="EchoText">
      <wsdl:input message="tns:EchoTextRequest"/>
      <wsdl:output message="tns:EchoTextResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="NewWSDLFileSOAP" type="tns:NewWSDLFile">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="EchoText">
      <soap:operation soapAction="http://192.168.1.2:10088/csc/NewWSDLFile/EchoText"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="NewWSDLFile">
    <wsdl:port binding="tns:NewWSDLFileSOAP" name="NewWSDLFileSOAP">
      <soap:address location="http://192.168.1.2:10088/csc/csc.php"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

更新..

我可以通过 try catch 和 print_r($e); 获得有关错误消息的更多详细信息...这里是详细的错误消息:


SoapFault Object (
  [message:protected] => Not Found
  [string:private] =>
  [code:protected] => 0
  [file:protected] => /www/zendserver/htdocs/dev/csc/request.php
  [line:protected] => 7
  [trace:private] => Array ( 
    [0] => Array (
      [function] => __doRequest
      [class] => SoapClient
      [type] => ->
      [args] => Array (
         [0] =>
         [1] => http://192.168.1.2:10088/csc/csc.wsdl
         [2] => http://www.example.org/NewWSDLFile/EchoText
         [3] => 1
         [4] => 0
      )
    )
   [1] => Array (
      [function] => __call
      [class] => SoapClient
      [type] => ->
      [args] => Array (
         [0] => EchoText
         [1] => Array (
             [0] => test
         )
      )
    )
   [2] => Array (
      [file] => /www/zendserver/htdocs/dev/csc/request.php
      [line] => 7
      [function] => EchoText
      [class] => SoapClient
      [type] => ->
      [args] => Array ( 
         [0] => test
      )
    )
  )
  [faultstring] => Not Found
  [faultcode] => HTTP
) 

【问题讨论】:

  • [0] => 数组 ( [function] => __doRequest [class] => SoapClient [type] => -> [args] => Array ( [0] => [1] = > 192.168.1.2:10088/csc/csc.wsdl 看来,您的 WSDL 文件被误解了。这只是一个疑问,可能对您有所帮助

标签: php xml web-services soap wsdl


【解决方案1】:

SoapFault => Not Found 是 SoapClient 无法访问服务器。

192.168.1.2 是本地 IP 地址,Web 服务器是否也在本地网络上?否则,这就是您的客户端无法正常工作的原因。

【讨论】:

  • 本项目中使用和引用的所有内容都在我们的本地网络上。除了 wsdl 的“schemas.xmlsoap.org/wsdl/soap”部分。我确实发现了一件有趣的事情,在我帖子底部的详细错误消息中,您会看到“example.org/NewWSDLFile/EchoText”,但这不在我的任何文件中!我还清除了我的缓存以确保它是当前的......我不知道这是如何进入那里的。
  • 您使用什么语言编写 Web 服务?
  • PHP,5.2.13 使用 apache 服务器。
  • 我在另一个问题上继续这篇文章。由于错误消息和问题已更改...尽管使用的 URL 仍然相同。 stackoverflow.com/questions/7561604/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2017-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多