运行soapclient时出现内部服务器错误

时间:2013-09-13 20:47:57

标签: php soap-client

这对于专业人士来说应该是一个简单的方法。我正在使用soapClient php库进行简单的调用(参见下面的代码)。

    

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
        $url = "http://webservices.daehosting.com/services/TemperatureConversions.wso?WSDL";

        $client = new SoapClient($url, array("trace" => 1, "exception" => 0)); 

        var_dump($client->__getFunctions());

        $SOAPCall = "CelciusToFahrenheit";
        $SoapCallParameters = "30";
        $obj = $client->CelciusToFahrenheit($SoapCallParameters);
        var_dump($obj);

        var_dump($client->getLastRequest());
    ?>

</body>

当我执行时,我得到以下错误。我查看了Apache错误日志,我看到了同样的错误。

Fatal error: Uncaught SoapFault exception: [HTTP] Internal Server Error in C:\wamp\www\phpSandbox\index.php:16 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://webservi...', '', 1, 0) #1 C:\wamp\www\phpSandbox\index.php(16): SoapClient->__call('CelciusToFahren...', Array) #2 C:\wamp\www\phpSandbox\index.php(16): SoapClient->CelciusToFahrenheit('30') #3 {main} thrown in C:\wamp\www\phpSandbox\index.php on line 16

我也从那些面临类似问题但未能找到解决方案的人那里做了一些阅读。

我确定已激活soapClient库,因为以下代码可以正常工作

var_dump($client->__getFunctions());

输出:

array (size=4)
  0 => string 'CelciusToFahrenheitResponse CelciusToFahrenheit(CelciusToFahrenheit $parameters)' (length=80)
  1 => string 'FahrenheitToCelciusResponse FahrenheitToCelcius(FahrenheitToCelcius $parameters)' (length=80)
  2 => string 'WindChillInCelciusResponse WindChillInCelcius(WindChillInCelcius $parameters)' (length=77)
  3 => string 'WindChillInFahrenheitResponse WindChillInFahrenheit(WindChillInFahrenheit $parameters)' (length=86)

解决此错误的任何帮助以及错误的可能解释都会很棒。

1 个答案:

答案 0 :(得分:6)

Internal Server Error通常意味着服务器得到了您的请求,但它不喜欢其中一个参数。

查看您的WSDL我可以看到CelciusToFahrenheit期望一个具有此定义的参数:

<xs:complexType>
 <xs:sequence>
    <xs:element name="nCelcius" type="xs:decimal"/>
 </xs:sequence>
</xs:complexType>

复杂类型是一个对象。所以试试这个:

$SoapCallParameters = new stdClass();
$SoapCallParameters->nCelcius = 30;
$obj = $client->CelciusToFahrenheit($SoapCallParameters);
相关问题