首页 文章

PHP SOAP扩展与WSDL抛出已发送的标头

提问于
浏览
0

承认这个问题已被多次询问并且我没有遇到接近我的情况的解决方案这一事实我没有选择,只能发布我自己的查询 .

下面是我写的一个简单的类,我通过php2wsdl库转换为wsdl文件 .

class MyClass
{
  /**
   * Adds two numbers.
   *
   * @soap
   *
   * @param float $p1
   * @param float $p2
   * @return float
  */
  public function getSum($num1, $num2){
     return $num1 + $num2;
    }
 }

我在wsdl文件的图像下面有includexd,因为格式化问题我可能会在这里输入它,所以我很抱歉:

enter image description here

我有一个客户端,我查询此服务,但我不知道我做错了什么 . 我知道所有现有的库,如Zend_AutoDiscovery和东西,但真的想要从头开始理解PHP Soap背后的概念 .

require_once __DIR__ . '/../../../php2wsdl.php';
ini_set('default_socket_timeout', 600);

try {

  $client = new \SoapClient(__DIR__ . '/../input/myclass.wsdl', array(
     'connection_timeout'=>5,
     'trace'=>true,
     'soap_version'=>SOAP_1_2
   ));

 $myClass = new \MyClass();

 /* var_dump($client->__getFunctions());
 exit();*/

 $result =  $client->__soapCall('getSum', array('MyClass' => $class, 'num1' => 17, 'num2' => 5));
 printf("Result = %s\n", $result);

} catch (Exception $e) {
  printf("Message = %s\n",$e->__toString());
}

警告:未捕获的SoapFault异常:[HTTP]错误在D:\ web \ webserv-bundle \ web \ services \ process \ myclass_client.php中获取http标头:19堆栈跟踪:#0 [内部函数]:SoapClient - > __ doRequest( 'http:// localhos ...','http:// localhos ...',2,0)#1 D:\ web \ webserv-bundle \ web \ services \ process \ myclass_client.php(19): SoapClient - > __ soapCall('getSum',Array)#2 D:\ web \ webserv-bundle \ web \ services \ index.php(3):require_once('D:\ web \ webserv -...')#3 在第19行的D:\ web \ webserv-bundle \ web \ services \ process \ myclass_client.php中抛出

2 回答

  • 0

    你应该增加套接字超时 .

    在你的php.ini文件中

    default_socket_timeout = 480
    

    也改为1,

    'trace'=>1
    

    希望它能帮到你:)

  • 0
    $result = $client->getSum(17, 5);
    

    好的,你需要3个文件:

    带有MyClass的

    • soap服务器

    • wsdl

    • 肥皂客户端


    soap服务器:webserv-bundle / web / services / index.php

    <?php
    
    class MyClass
    {
        public function getSum($num1, $num2){
            return $num1 + $num2;
        }
    }
    
    ini_set("soap.wsdl_cache_enabled", "0");
    
    $server = new SoapServer("http://path_to_your_wsdl");
    
    $server->setClass("MyClass");
    
    $server->handle();
    

    wsdl文件 - 你已经有了这个文件

    必须可以在浏览器中访问此文件 http://path_to_your_wsdl


    肥皂客户端 - soapclient.php

    <?php
    
    $client = new SoapClient(
        "http://path_to_your_wsdl",
        array( 'soap_version' => SOAP_1_2)
    );
    
    var_dump($client->getSum(55,4));
    

    然后在浏览器中 - http://path_to_my_project/soapclient.php

相关问题