Php通过gsoap调用c++ websevice



Php通过gsoap调用c++ websevice

由于工作的关系,需要通过php调用c++使用gsoap编写的websevice,其中遇到了很多困难,特此进行总结如下,也方便大家以后的使用和提高。

其中服务端采用c++编写而成,客户端采用php编写而成。

 

一:使用c++编写websevice服务端

        1.c++通过gsaop编写websevice的教程很多,就不详细介绍了,当时使用的是gsoap_2.8.17,编写的代码如下:

    
//gsoap ns service name: query
//gsoap ns service namespace:http://172.16.6.86:9090/query.wsdl
//gsoap ns service location:http://172.16.6.86:9090/query
//gsoap ns service executable: query.cgi
//gsoap ns service encoding: encoded
//gsoap ns schema namespace: urn:query
#include
   
   
    
    
#include
    
    
     
     

int ns__query(std::string startTime,std::string endTime,int baseType,int subType,std::string carId, std::wstring&pResponse);

    
    
   
   

   

在这之上,搭建好需要的websevice服务端。

 

二:php编写客户端

   Php在编写客户端的过程中,遇到了很多连接问题,诸如不能启动soap协议,乱码等问题。关于乱码的解决,请看我的上一篇博客。

   我采用的是wampserver来编写客户端,在使用soap协议之前,请确保wamoserver已经开启了soap协议。

Php的代码如下:其中红字的部分需特别注意,变量的名称一定要和服务端变量的名称相对应:

<?php

$ws ="http://172.16.6.86:9090/query.wsdl";

   $soap= newSoapClient("http://172.16.6.86:9090/query.wsdl",array('location'=>"http://172.16.6.86:9090",'uri'=>"urn:query",'connection_timeout'=>60,));

       var_dump($soap);

       

       $client= new SoapClient ($ws);

       $s="";

       $result =$client->query(array("startTime"=>"2015-01-2700:00:01","endTime"=>"2015-01-2715:00:01","baseType"=>0,"subType"=>0,"carId"=>"1","sum"=>$s));

       print_r($result);

       

?>

 

相信看到这里,大家也能够只做自己的websevice了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值