dousonghs58612 2014-11-21 19:04
浏览 68

如何在PHP中访问Windows Web服务

I want to access some of my client's data through a web service. He has provided me below information to get this data in XML format.

http://www.clients-domain.com/erpsync/erp_sync.asmx

User = abcd

Password = 1234

Detail of Functions:

GetAllItemData - Will return all the items selected for web, with their price

GetItemDataByDate - Will return all the items updated between a specific date

GetAllItemStock - Will return updated stock of all items for website

GetStockByItem - Will return stock of single Item.

This web service is on a windows based server.

I dont know how to call above URL in PHP to get this data. He told me that the return value of this web service would be in XML format.

Also it is SOAP 1.1

Any help appriciated

  • 写回答

1条回答 默认 最新

  • duanshan1511 2014-11-21 19:08
    关注

    Since he stated SOAP simple extend the soap client

    1st establish a connection to the SOAP

    $soapCon = new Utils_SoapClient("http://www.clients-domain.com/erpsync/erp_sync.asmx", array());
    $soapCon->setCredentialsHeader(User, Password);
    

    Create a struct to pass variables

    $struct = new stdClass();
    $struct->item1 = $item1;             
    

    Call functions that client gives you with passed parameters / variables

    GetAllItemData - Will return all the items selected for web, with their price

    $result = $soapCon->GetAllItemData(new SoapVar($struct, SOAP_ENC_OBJECT));
    

    GetItemDataByDate - Will return all the items updated between a specific date

    $result = $soapCon->GetItemDataByDate(new SoapVar($struct, SOAP_ENC_OBJECT));
    

    GetAllItemStock - Will return updated stock of all items for website

    $result = $soapCon->GetAllItemStock(new SoapVar($struct, SOAP_ENC_OBJECT));
    

    GetStockByItem - Will return stock of single Item.

    $result = $soapCon->GetStockByItem(new SoapVar($struct, SOAP_ENC_OBJECT));
    

    Soap Client Class

    class Utils_SoapClient extends SoapClient {
    
       protected $_targetNamespace;
    
       public function __construct($wsdl, $options){
               parent::__construct($wsdl, $options);
    
               // detect target namespace
               $xml = simplexml_load_file($wsdl);
               $this->_targetNamespace = (string) $xml['targetNamespace'];
       }
    
       public function setCredentialsHeader($login, $password) {
               $header = new SoapHeader($this->_targetNamespace,
                       'CredentialsSoapHeader',
                       new SoapVar(
                               array(
                                       'Login' => $login,
                                       'Password' => $password,
                               ),
                               SOAP_ENC_OBJECT,
                               'CredentialsSoapHeader',
                               $this->_targetNamespace
                       )
               );
    
               $this->__setSoapHeaders(array($header));
       }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真