posts - 12,  comments - 6,  trackbacks - 0

http://sourceforge.net/projects/gsoap2 下载最新的gSoap

 

在其目录下找到VisualStudio2005 可以直接在Windows环境下编译该文件

阅读readme.txt 需要安装bisonflex 两个编译软件。

分别在以下两个链接中下载。

http://gnuwin32.sourceforge.net/packages/bison.htm

http://gnuwin32.sourceforge.net/packages/flex.htm

安装时候注意目录中不要含有空格,我最开始安装的时候安装在 C:\Program Files (x86)\GnuWin32 目录下结果,在vs编译的时候,指定的目录识别有问题,最后卸载重新安装到 C:\GnuWin32 中便没有问题了。

 

分别编译 soapcpp2 wsdl2h 两个工程。

 

首先是 soapcpp2

打开项目便提示错误:

 

   

 

解决办法:

下载下面文件

http://download.microsoft.com/download/3/f/9/3f9f31b7-61a4-4dd6-9170-36d5b1d9356c/vccustombr.exe

安装,然后把FlexBison.rules文件拷贝到 gsoap/VisualStudio2005/soapcpp2 目录下面

 

用记事本打开gsoap/VisualStudio2005/soapcpp2/soapcpp2/soapcpp2.vcproj

把里面的
"RelativePath="../../../../../../../MSDN/Sample/VC++/vccustombr/FlexBison.rules"
替换成
"RelativePath="./FlexBison.rules"

好了,现在再打开soapcpp2.vcproj文件,可以打开了

 

在编译的时候会遇到问题,因为编译时候,soapcpp2_lex.l soapcpp2_yacc.y 的时候,会用到flex.exe bison.exe

        
         

 

所有需要将安装的 bisonflex 设置下链接。


    


这样就编译没有问题了。

 

编译 wsdl2h 工程,没有什么问题,可以直接编译。

 

找到生成的soapcpp2.exe wsdl2h.exe

 

下面开始 编写个客户端跟Web Service 服务端通信。

 

ClientPlaceService.wsdl 服务端 wsdl 的内容如下

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3-hudson-390-. -->
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://Server/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ClientPlaceService" targetNamespace="http://Server/">
  
<types>
    
<xsd:schema>
      
<xsd:import namespace="http://Server/" schemaLocation="ClientPlaceService_schema1.xsd"/>
    
</xsd:schema>
  
</types>
  
<message name="LoginByPassWord">
    
<part element="tns:LoginByPassWord" name="parameters"/>
  
</message>
  
<message name="LoginByPassWordResponse">
    
<part element="tns:LoginByPassWordResponse" name="parameters"/>
  
</message>
  
<message name="UpdateMoney">
    
<part element="tns:UpdateMoney" name="parameters"/>
  
</message>
  
<message name="UpdateMoneyResponse">
    
<part element="tns:UpdateMoneyResponse" name="parameters"/>
  
</message>
  
<portType name="ClientPlaceDelegate">
    
<operation name="LoginByPassWord">
      
<input message="tns:LoginByPassWord"/>
      
<output message="tns:LoginByPassWordResponse"/>
    
</operation>
    
<operation name="UpdateMoney">
      
<input message="tns:UpdateMoney"/>
      
<output message="tns:UpdateMoneyResponse"/>
    
</operation>
  
</portType>
  
<binding name="ClientPlacePortBinding" type="tns:ClientPlaceDelegate">
    
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    
<operation name="LoginByPassWord">
      
<soap:operation soapAction=""/>
      
<input>
        
<soap:body use="literal"/>
      
</input>
      
<output>
        
<soap:body use="literal"/>
      
</output>
    
</operation>
    
<operation name="UpdateMoney">
      
<soap:operation soapAction=""/>
      
<input>
        
<soap:body use="literal"/>
      
</input>
      
<output>
        
<soap:body use="literal"/>
      
</output>
    
</operation>
  
</binding>
  
<service name="ClientPlaceService">
    
<port binding="tns:ClientPlacePortBinding" name="ClientPlacePort">
      
<soap:address location="http://localhost:8080/DwPadWS/ClientPlacePort"/>
    
</port>
  
</service>
</definitions>


链接的服务器的地址为:

http://192.168.18.129:8080/DwPadWS/ClientPlacePort?wsdl

 

这样我们做一个test_xm文件夹 开始写测试程序吧。

soapcpp2.exe wsdl2h.exe 拷贝到 test_xm 目录下。

运行cmd 命令行。

 

wsdl2h -o DwPadWS.h http://192.168.18.129:8080/DwPadWS/ClientPlacePort?wsdl

 

soapcpp2 -i -C -x DwPadWS.h -I ..\gsoap\import

命令选项注释:

-i 直接使用C++包装类 -x 不要生成一堆看了就恶心的xml -C 只生成客户端相关代码 -I 指定import路径

 

此时生成 如下

         

vs创建工程 test,为了方便建一个命令行的工程

将上面的 所有文件(不包括exe文件)、以及gsoap目录下的stdsoap2.hstdsoap2.cpp文件拷贝工程目录下,并加到工程中。

#include "stdafx.h"
#include 
"soapClientPlacePortBindingProxy.h"
#include 
"ClientPlacePortBinding.nsmap"

int _tmain(int argc, _TCHAR* argv[])
{
    ClientPlacePortBindingProxy kDwPadWS;

    ns1__LoginByPassWord PassWord;
    PassWord.arg0 
= 0;
    std::
string strUserName = "test02";
    PassWord.arg1 
= &strUserName;
    std::
string strPassWord = "123";
    PassWord.arg2 
= &strPassWord;
    std::
string strPCID = "nothing";
    PassWord.arg3 
= &strPCID;
    ns1__LoginByPassWordResponse PassWordResponse;
    PassWordResponse.return_ 
= 0;
    
if( kDwPadWS.LoginByPassWord(&PassWord, &PassWordResponse) == SOAP_OK )
    
{
        std::cout 
<< PassWordResponse.return_ << std::endl;
    }

    
else
    
{
        kDwPadWS.soap_stream_fault(std::cerr);
    }

    Sleep(
5000);

    
return 0;
}



posted on 2012-10-10 14:25 vic.MINg 阅读(4047) 评论(0)  编辑 收藏 引用 所属分类: Open Source

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(1)

随笔分类(13)

随笔档案(12)

搜索

  •  

最新评论

阅读排行榜

评论排行榜