dongyuruan2957 2013-08-30 10:57
浏览 58
已采纳

php命名空间内的SoapClient类映射 - 找不到soapfault类

I've generated a set of php classes using easyWsdl2PHP and they are working ok, but when I place the generated class inside a namespace like such...

namespace myCompany\ourService

then initially when calling this code...

$params = array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true);     
$this->soapClient = new SoapClient($url,$params);

I get this error

Class 'myCompany\ourService\SoapClient' not found

which I fix by calling new \SoapClient($url... (notice the backslash at the start, escapes the namespace), but now basically it is complaining it cant find the 'response' object, that is my Request is placed in a 'SALE' object and passed to the soap call, the error is like so

Uncaught SoapFault exception: [Client] Class 'SALEResponse' not found

How can I use php namespaces correctly within my code, how to get Soap in php to use the name spaces correctly? I have two very similar services I need to connect to, both with 'sale' methods, and many other commonly named elements that are not compatible, so placing them inside a php namespace appears to be a good solution, as the code is generated, I could rename each Sale to Service1_Sale and Service2_Sale, but that is far from ideal. Any help?

  • 写回答

1条回答 默认 最新

  • doufunuo4787 2013-08-30 14:13
    关注

    I've found a solution :

    private static $classmap = array('SALE'=>'ourCompany\ourService\SALE'
    ,'SALEREQUEST_V1'=>'ourCompany\ourService\SALEREQUEST_V1'
    ,'AUTHORIZATION_V1'=>'ourCompany\ourService\AUTHORIZATION_V1'
    ,'RECEIPTREQUEST_V1'=>'ourCompany\ourService\RECEIPTREQUEST_V1'
    ,'SALEResponse'=>'ourCompany\ourService\SALEResponse'
    );
    

    where i've added the ourCompany\ourService\ to include the namespace i'm using.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败