`
bruce008
  • 浏览: 172899 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Web Service Client tool Evaluation

阅读更多

 

In the MFC/C++ environment, there are several libraries/tools can be used to integrate with Java Web Service. They are ATL Server, Windows Web Service API and gSoap.

1, ATL Server

ATL Server is C++ Template based technology in Vistual Studio environment.It provides an utility tool to generate proxy code for Web Service client. From Visual Studio 2008, Mirosoft open sourced it, and its official Web site is http://atlserver.codeplex.com. We can download the ATL_Server_Source_and_Headers_9_0_70425_Alpha.zip.  After unzipping this file,  we can find a  solution file under the source sub folder for this tool. It is in the VS 2005 version, which need converted into  VS 2008 version once we double click it to open it. Open the solution file, add the ATL Server include folder in the property

 Then build this sproxy.sln , we can get the sproxy.exe utility.

In Microsoft MSDN, We can find some useful link about how to use the sproxy.exe.

  sproxy [ options ] [ /out:outputfile ] input_location

 

The input_location can be a local WSDL file or  HTTP link for a WSDL.

For example:

 

sproxy /wsdl http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?WSDL

 

will generate a header file  WeatherWS.h.We can add this file in our Web Service Client project to access like:

 

#include "WeatherWS.h"

using namespace WeatherWS;

 

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])

{

    CoInitialize(NULL);

    HRESULT hr = S_OK;

    CWeatherWST<CSoapSocketClientT<>> * m_srv = new CWeatherWST<CSoapSocketClientT<>>;

    CComBSTR cityCode = "";

    CComBSTR userId = "";

    CComBSTR * bstrOut;

    int size;

    hr = m_srv->getWeather(cityCode, userId, (BSTR * *)&bstrOut, &size);

    if(FAILED(hr))

    {

    }

    else

    {

            std::cout << bstrOut->m_str << std::endl;

    }

    if (m_srv != NULL)

        delete m_srv;

    CoUninitialize();

      return 0;

}

 

This snippet of code can run successfully.

But when we generate some other Web Service WSDL file, the generated file will cause runtime exception. We created the Web Service – User Detail to get available application for specific user. The WSDL content for this Web Service is listed following:

 

 

<?xml version="1.0" encoding="UTF-8" ?>

- <wsdl:definitions name="UserDetailServiceImplService" targetNamespace="http://security.ipns.enterprise.argushealth.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://security.ipns.enterprise.argushealth.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

- <wsdl:types>

- <xs:schema elementFormDefault="unqualified" targetNamespace="http://security.ipns.enterprise.argushealth.com/" version="1.0" xmlns:tns="http://security.ipns.enterprise.argushealth.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="getAvailableApplications" type="tns:getAvailableApplications" />

  <xs:element name="getAvailableApplicationsResponse" type="tns:getAvailableApplicationsResponse" />

- <xs:complexType name="getAvailableApplications">

- <xs:sequence>

  <xs:element minOccurs="0" name="arg0" type="xs:string" />

  </xs:sequence>

  </xs:complexType>

- <xs:complexType name="getAvailableApplicationsResponse">

- <xs:sequence>

  <xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="tns:application" />

  </xs:sequence>

  </xs:complexType>

- <xs:complexType name="application">

- <xs:sequence>

  <xs:element minOccurs="0" name="name" type="xs:string" />

  <xs:element minOccurs="0" name="url" type="xs:string" />

  </xs:sequence>

  </xs:complexType>

  </xs:schema>

  </wsdl:types>

- <wsdl:message name="getAvailableApplications">

  <wsdl:part element="tns:getAvailableApplications" name="parameters" />

  </wsdl:message>

- <wsdl:message name="getAvailableApplicationsResponse">

  <wsdl:part element="tns:getAvailableApplicationsResponse" name="parameters" />

  </wsdl:message>

- <wsdl:portType name="UserDetailService">

- <wsdl:operation name="getAvailableApplications">

  <wsdl:input message="tns:getAvailableApplications" name="getAvailableApplications" />

  <wsdl:output message="tns:getAvailableApplicationsResponse" name="getAvailableApplicationsResponse" />

  </wsdl:operation>

  </wsdl:portType>

- <wsdl:binding name="UserDetailServiceImplServiceSoapBinding" type="tns:UserDetailService">

  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />

- <wsdl:operation name="getAvailableApplications">

  <soap:operation soapAction="" style="document" />

- <wsdl:input name="getAvailableApplications">

  <soap:body use="literal" />

  </wsdl:input>

- <wsdl:output name="getAvailableApplicationsResponse">

  <soap:body use="literal" />

  </wsdl:output>

  </wsdl:operation>

  </wsdl:binding>

- <wsdl:service name="UserDetailServiceImplService">

- <wsdl:port binding="tns:UserDetailServiceImplServiceSoapBinding" name="UserDetailServiceImplPort">

  <soap:address location="http://172.16.23.25:9081/user-application-ws/UserDetail" />

  </wsdl:port>

  </wsdl:service>

  </wsdl:definitions>

 

 

After running

sproxy /wsdl http://172.16.23.25:9081/user-application-ws/UserDetail?wsdl

We add the generated file UserDetailServiceImplService.h to RSOClient project, use the following snippet of code to access the Web Service:

 

 

#include "UserDetailServiceImplService.h"

using namespace UserDetailServiceImplService;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])

{

      CoInitialize(NULL);

    HRESULT hr = S_OK;

    CUserDetailServiceImplServiceT<CSoapSocketClientT<>> * m_srv = new CUserDetailServiceImplServiceT<CSoapSocketClientT<>>;

    CComBSTR userId = "charles";

    CComBSTR * bstrOut;

    int size;

      getAvailableApplications arg;

      application AvailableApplicationsResponse;

      application* p = &AvailableApplicationsResponse;

      application** ppAvailableApplicationsResponse = &p;

      arg.arg0 = L"charles";

      hr = m_srv->_getAvailableApplications(arg,    ppAvailableApplicationsResponse, &size);

    if(FAILED(hr))

    {

            std::cout<< L"fail" << std::endl;

    }

    else

    {

        for (int i = 0; i < size; i++)

        {

      std::cout << ppAvailableApplicationsResponse[i]->name << std::endl;

      std::cout << ppAvailableApplicationsResponse[i]->url << std::endl;

        }

    }

    if (m_srv != NULL)

        delete m_srv;

    CoUninitialize();

}

 

 

hr = m_srv->_getAvailableApplications(arg,    ppAvailableApplicationsResponse, &size);

Always goes to

    if(FAILED(hr))

    {

            std::cout<< L"fail" << std::endl;

    }

 

After carefully debugging we found that the generated proxy is sending incorrect SOAP content. From the captured the network package, we can see

 

There are one more <getAvailableApplications> sub element under <getAvailableApplications>. But from the WSDL file, the getAvailableApplications element should be

The element arg0 is the direct child element of getAvailableApplications. When we evaluated the gSOAP, we found that gSOAP generates the correct format.

 

2, Windows Web Service API

 WWSAPI is a native-code implementation of SOAP which provides core network communication functionality by supporting a set of the WS-* and .NET-* family of protocols. WWSAPI is designed to be used by components/applications which fall into one of the following categories:

 

  • Native code mandate
  • Require minimal dependencies
  • Require minimal startup time
  • Memory constrained environments

Windows Web Services API (WWSAPI) is an operating-system component of the following operating systems:

 

  • Windows 7
  • Windows Server 2008 R2
  • XP   SP3
  • Vista

Windows Web Services API  sounds like a perfect option for us, all the original download link are not available now. It needs us send formal business email to Microsoft  to get redistributable installers.   We mainly referenced to  this official blog  of MSDN . http://blogs.msdn.com/b/windowssdk/archive/2009/10/20/building-web-services-on-windows-with-c.aspx

 

3, gSOAP

   The official web site for gSOAP is   http://sourceforge.net/projects/gsoap2. From there we can learn that:

 The gSOAP toolkit is a portable C and C++ software development toolkit for XML Web services and generic XML data bindings. Easy-to-use XML auto-serialization allows you to directly integrate C and C++ data with XML. Includes WSDL/XSD schema binding and auto-coding tools, stub/skeleton compiler, Web servers (with SSL), integrated XML processing with schema validation, fast MIME/MTOM streaming, SOAP and REST, WS-* protocols (WS-Security, WS-Policy, etc), XML-RPC and JSON serialization.

 

 Currently the stable version is 2.8.8.After download  and unzip  the gsoap_2.8.8.zip file, we can find there are two binary tools  under the sub folder gsoap/bin/win32:

      wsdl2h.exe   

      soapcpp2.exe

There is also source code for them under the src folder. Of course we can build  both of them from scratch. There is VisualStudio2005 folder, under which the Readme is very importance.  Follow  the Readme, we can also build the two tools by ourselves .

 

 

 The two tools has some function as  sproxy.exe in ATL Server.  The difference is we need do it with two steps. First we use wsdl2h to generate a header file , then use soapcpp2 to generate the files we need use in our project base on this header file. For example:

       1, wsdl2h -o  userservice.h -n namespacename  URL or file name

          the generatd userservice.h file will be used in the next step. 

       2, soapcpp2  userservice.h -C -i -x -I F:\study_code\mfc\gsoap_2.8.8\gsoap-2.8\gsoap\import

                  

            F:\study_code\mfc\gsoap_2.8.8\gsoap-2.8\gsoap\import  is the import folder under the gsoap.

        soapcpp2 will generate totally fix files:

 

  •   soaph.h
  •  soapc.cpp
  •   soapStub.h
  •  soapUserDetailServiceImplServiceSoapBindingProxy.cpp
  •  soapUserDetailServiceImplServiceSoapBindingProxy.h
  • UserDetailServiceImplServiceSoapBinding.nsmap

 

After generating the files , we need use the files in our Web Service client project. Except the generated files, we also need other two files :   stdsoap2.h, stdsoap2.cpp ( they are under the gSoap folder).   We can use the following snippet of code :

 

#include "UserDetailServiceImplServiceSoapBinding.nsmap"

#include "soapUserDetailServiceImplServiceSoapBindingProxy.h"

const char endpoint[] = "http://172.16.23.25:9081/user-application-ws/UserDetail";

 

CReEngiApps GetApps(const char* userId)

{

      CReEngiApps  apps;

 

      UserDetailServiceImplServiceSoapBindingProxy  proxy(SOAP_XML_INDENT);

      rso1__getAvailableApplications rso1__getAvailableApplications_;

      rso1__getAvailableApplicationsResponse rso1__getAvailableApplicationsResponse_;

 

      std::string user = userId;

      rso1__getAvailableApplications_.arg0 = & user;

      int ret = proxy.getAvailableApplications(endpoint, NULL, &rso1__getAvailableApplications_,  &rso1__getAvailableApplicationsResponse_);

      if (ret == SOAP_OK)

      {

            std::vector<rso1__application * > & applications = rso1__getAvailableApplicationsResponse_.return_;

            apps.m_appNum = applications.size();

            for (int i=0; i < apps.m_appNum; i++)

            {

                  memcpy(apps.m_apps[i].m_szAppName, applications[i]->name->c_str(), strlen(applications[i]->name->c_str()));

                  memcpy(apps.m_apps[i].m_szAppUrl, applications[i]->url->c_str(), strlen(applications[i]->url->c_str()));

            }

      } else

      {

            apps.m_appNum = 0;

      }

      return apps;

}

 

ATL Server VS gSOAP

    1, ATL Server is C++ template based.Its generated code has lots of template code. Template code is much harder than normal code to understand.gSOAP generates simple code, event only C code.

2, ATL Server has a fatal issue, we found, it generates incorrect SOAP content, which can cause request failed. So far, the code generated by gSOAP is good, no big issue.

 

Conclution

   gSOAP is an open source tool can generate portable C/C++ Web Service proxy code.The generated code is easy to use.

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    axis web service client 源码

    axis web service client 源码

    java jenkins web service client

    Java Jenkins Web Service Client是用于与Jenkins CI服务器交互的一种客户端工具,它允许开发者通过编程方式执行Jenkins的各种操作,如创建、更新、删除Job等。这个客户端基于Java编写,能够方便地集成到Java项目中...

    Rest-Web-Service-Client_v3.6.0.crx.zip

    首先,"Rest-Web-Service-Client_v3.6.0.crx"是一个Chrome浏览器扩展,用于测试和调试RESTful Web服务。CRX文件是Chrome浏览器的插件或扩展的打包文件格式,它包含了一款扩展的所有必要资源,如HTML、CSS、...

    web service client

    Web服务客户端(Web Service Client)是一种能够调用远程Web服务的工具或库,它使得开发者能够在自己的应用程序中利用网络上提供的各种服务。在本场景中,我们关注的是使用Liferay的Web Service Client来通过Java...

    C#Web Service C#Web Service C#Web Service

    C# Web Service是一种基于.NET Framework的开发技术,用于创建分布式应用程序,使得不同系统间能够通过互联网进行通信。这种服务提供了一种标准化的方式,允许应用程序通过HTTP协议交换数据,因此,即使它们是由不同...

    VMware vSphere Web Client操作篇

    VMware vSphere Web Client 操作篇 VMware vSphere Web Client 是 VMware vSphere 的一个主要组件,提供了基于 Web 的界面,用于管理和监控 VMware vSphere 环境。下面我们将详细介绍 VMware vSphere Web Client 的...

    Web Service SOAP Client set SOAP Header

    当涉及到Web Service客户端与服务器之间的交互时,有时需要在SOAP消息中添加额外的信息,例如身份验证或安全凭证,这就是SOAP Header的作用。SOAP Header是SOAP Envelope的一部分,它允许扩展和自定义消息处理。 在...

    asp.net写的web service例子

    ASP.NET Web Service是一种基于.NET Framework的简单方法,用于构建可跨平台、跨语言通信的Web应用程序。这个例子是为初学者设计的,旨在演示如何创建和使用Web Service,以及如何在ASP.NET环境中调用这些服务。 ...

    CXF Web Service & client

    本篇将深入探讨如何利用CXF来开发Web Service及其客户端,以及相关的重要知识点。 ### 1. CXF简介 Apache CXF是一个全面的服务框架,支持多种Web服务规范,如SOAP、RESTful API、WS-*(如WS-Security、WS-...

    jdk5 下 CXF 开发 WEB Service client 所需jar 包

    在Java开发领域,Web服务(Web Service)是一种用于应用程序之间进行通信的标准协议,它使得不同系统之间能够交换数据。在JDK 5环境下,Apache CXF是一个常用的框架,用于开发和消费Web服务,无论是作为服务提供者...

    T100 Web Service 接口开发v1.5版.rar

    “cwssp002(c).tzc”和“cs_erp_wms_client(c).tzc”可能是客户端库或配置文件,它们可能包含了与T100 Web Service交互所需的一些预编译代码或者配置信息,使得集成变得更加简便。 综上所述,T100 Web Service接口...

    Web service应用实例

    ### Web Service应用实例详解 #### 一、IIS安装与配置 在开发Web Service之前,首先需要确保服务器上已正确安装并配置了Internet Information Services (IIS)。无论是Windows Server 2003还是Windows XP,IIS都是...

    Java完整的Web Service示例代码,学会做web service程序

    本示例代码将帮助你理解和实现一个完整的Web Service程序。 首先,我们来看"xfire-client"部分。XFire是早先的一个Java Web Service框架,它简化了客户端和服务端的开发。在Java中,创建Web Service客户端通常涉及...

    WCF Service Client

    这使得服务可以通过Web浏览器或者HTTP客户端(如WCF Service Client)访问。在配置WCF服务以使用HTTP协议时,我们需要在服务配置文件(web.config或app.config)中指定使用HttpBinding。例如: ```xml &lt;!-- ...

    sonar-web-service-client:用于访问 SonarQube 的 Web API 的客户端函数

    `sonar-web-service-client` 就是一个专门设计用于访问这个 Web API 的客户端库。 在 Java 开发中,使用 `sonar-web-service-client` 可以方便地集成到项目中,执行自动化任务,如获取项目质量报告、触发分析、更新...

    Web Service 开发实例 文档 1.4 wsdd client 完整

    在"Web Service 开发实例 文档 1.4 wsdd client 完整"这个主题中,我们可以深入学习以下几个关键知识点: 1. **Web Service描述语言(WSDL)**: WSDL(Web Services Description Language)是XML格式的规范,用于...

    jssip-web-client.zip_JsSIP CLIENT_jssip 4_web sip_webrtc sip_基

    这个"jssip-web-client.zip"压缩包包含了构建一个基于Web的SIP电话客户端所需的所有资源,特别是针对版本4的JsSIP。SIP是一种标准的协议,广泛应用于VoIP通信,用于建立、修改和终止多媒体会话,如语音和视频通话。 ...

    8 XFire Web Service 入门.doc

    如果需要创建一个独立的项目作为Web服务的客户端,可以通过"New -&gt; Web Service Client"来完成。这样可以生成一个与服务交互的完整客户端项目结构。 8. **根据WSDL和JAXB生成客户端代码** WSDL文件和Java ...

    JAVA程序调用Web Service示例过程演示

    在NetBeans中,你可以通过右击项目,选择“New”&gt;“Other”&gt;“Web Services”&gt;“Web Service Client”,然后按照向导填写指定客户端的位置和WSDL文件的URL。 ### 四、创建Java类文件 为了实现业务逻辑和处理Web ...

Global site tag (gtag.js) - Google Analytics