C + + through gSOAP to do WebService interface for C + + and Java client calls __c++

Source: Internet
Author: User
Tags emit soap soap client knowledge base wsdl


Problem Description:
The original project is compiled on the VS2005, with VC write, and I now use the VS2008, in the compile times wrong said "Atlsoap.h": No such file or directory, online find the solution is http:// Www.enjoyit.com.cn/bbs/dispbbs_36_5649.html. Recently in the above code, recompile found another problem: Error PRJ0003: Generate "Sproxy.exe" error.

Method:

I later found sproxy in source and compiled this project. At first it didn't work out because the properties of the folder are read-only, and when you get rid of it, recompile. Finally, put the generated sproxy.exe (in the Debug folder) in the directory where you installed vs. /microsoft Visual Studio 9.0/vc/bin can solve the problem.


In Visual Studio 2008 and later, Microsoft stopped direct WebService references to unmanaged C + +. However, ATL Server code is already hosted on the open source Web site, we can find the source code of ATL Server, compile the Sproxy.exe, the tool can generate unmanaged proxy class according to the WSDL file. This proxy class also needs some header files to work with, and the associated header file is included in the ATL Server's source code.

1. The first step requires the use of the Sproxy.exe tool to generate the proxy class. The previous version of VS2008, such as VS2005, had the command itself, but in the vs2008 version, it had been removed. Need to http://atlserver.codeplex.com/download Atl_server source code (latest atl_server_source_and_headers_9_0_70425_ Alpha) and compiles the resulting sproxy.exe tool.

Note: When the atl*.h file is not found at compile time, you need to locate and copy the Include files under the Atl_server_source_and_headers_9_0_70425_alpha directory into the C:\Program files\ MicrosoftVisual Studio 10.0\vc\atlmfc\include (that is, the VC installation directory).

2. In order to test the WebService service, I found a website offering webservice on the Internet: Http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx It provides weather services. Its WSDL file is in this: Http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?WSDL saves this file as a local file, named WEATHERWS.WSDL. For convenience, I assume that this file and sproxy.exe are placed in the same directory, executing the command

SPROXY.EXE/WSDL weatherws.wsdl

WeatherWS.h files are generated in the same directory.

3. Open VS2008, build an MFC project WebService, add WeatherWS.h files to the project header file. The Include directory path where the Atl_server is set in the project. Add in WebServiceDlg.cpp file

#include "WeatherWS.h"
using namespace Weatherws;

4. After these are done, you can call the WebService service, please refer to the attachment code.
[CPP]  View plain copy CoInitialize (NULL);      hresult hr = s_ok;        cweatherwst<csoapsocketclientt<>>* m_srv = newcweatherwst< csoapsocketclientt<>>;            ccombstr citycode=  "" The  //parameter is null default return to Shanghai weather       ccombstr userid=  "";       ccombstr * bstrout= null;       int size;        cstring strurl= _t ("Http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx");      M_srv->seturl (strURL)//Set URL address       m_srv->settimeout (5000);//Set timeout (parameter milliseconds)       Hr = m_srv->getweather (citycode,userid,  (bstr* *) &bstrout,  &size);       int nerrorcode = m_srv->getstatuscode ();nbsp;     if (FAILED (HR))        {          MessageBox (L "call failed");      }      else       {          for  (int i = 0; i < size;  i++)           {              bstrout[i]. Append ("\ r \ n");         }               if (bstrout!=null)          {              for (int i=size-1;i>=0;i--)               {                 ::sysfreestring (Bstrout[i]);             }             bstrout =  NULL;         }     }      if   (m_srv != null)           delete m_srv;        couninitialize ();  


SPROXY. EXE is a command-line tool that generates native C + + client code that accesses XML Web services based on a WSDL description.

The command line syntax looks like this:

Copy

sproxy [Options] [/out:outputfile] input_location Parameters

Options

Optionally, one or more of the following options:

Options

Description

/? or/help

Display usage information.

/nologo

Suppresses the display of copyright messages.

/nowarn

Disables all warnings.

/nopragma

Do not insert "#pragma once" into the output file.

/noclobber

If the output file already exists, it is not overwritten.

/nonamespace

Do not insert the C + + namespace into the generated proxy file. By default, SPROXY inserts a namespace based on the WSDL service name.

/namespace:<name>

Inserts a namespace named <name> into the generated proxy file. By default, SPROXY inserts a namespace based on the WSDL service name.

The namespace must be a valid C + + identifier. The,/namespace:<name> option has the same effect as/nonamespace when <name> is empty.

/WSDL <input_location>

Handles the. wsdl file located in the specified path <input_location>, not the default. discomap file.

OutputFile

(optionally) the name of the file that the generated code will write to. If the file exists, it will be overwritten unless/noclobber is specified. If Outputfile,sproxy is not specified, a file is created in the current directory based on the WSDL service name.

Input_location

The location of the file that describes the XML Web services that generated their proxy code. Input_location can be either a URL to a. discomap or. wsdl file or a file system path. When using the. wsdl file, specify the/WSDL option.

SPROXY. EXE can also process results.discomap files. Note that the. discomap file contains a link to a local copy of the. wsdl file and uses a local copy of the schema file. notes

SPROXY. EXE will generate a proxy class template derived from CSoapRootHandler and its template parameters. Template parameters need to conform to the SOAP client prototype and default to Csoapsocketclientt<>.

Each SOAP method exposed by a service is represented by a method in the proxy class. To access the XML webservices, create an instance of the proxy class and invoke the appropriate method.

SPROXY can be found in the \vc7\bin directory of the Visual C + + Setup program. Exe.

For a list of types supported by SPROXY, see Supported types and types supported in XML WEB services created with ATL Server.

Attention SPROXY generated clients need MSXML3. Before running the client, you will need to install MSXML3 on the computer where the client is being installed.

Xmlinst.exe installs MSXML3 in replacement mode. Please http://msdn.microsoft.com/downloads/default.asp from MSDN? Url=/code/sample.asp?url=/msdn-files/027/001/469/msdncompositedoc.xml Download Xmlinst.exe Replace Mode tool.

For information about using Xmlinst.exe, see the article in the Knowledge Base: "PRB: Application errors that occur after running Xmlinst.exe on a production server" (Q278636). KB articles can be found on the MSDN Library CD-ROM or http://support.microsoft.com/support/.

For information about running MSXML3, see Running MSXML 3.0 in replacement mode.

Attention The header file generated by SPROXY includes Atlsoap.h. This file declares [emitidl ("restricted")];. If the IDL emit is restricted when encountering the [module] property, an error occurs. After including Atlsoap.h, you can use [Emitidl ("true")] in your code to enable IDL emit. (Atlextmgmt.h includes the same emitidl declaration as atlsoap.h, so it adapts to the same problem.) )

Note The method generated by the SPROXY does not check whether the pointer parameter is NULL until the reference is canceled. Before you pass the pointer to a method in the XML Web Services proxy class, check to see if the pointer is NULL. Sample

The following command line generates a file myservice.h that contains a file for access from Http://myserver/myservice.dll. HANDLER=GENMYSERVICEWSDL gets the WSDL described by the XML webservices C + + proxy code:

Copy

Sproxy/wsdlhttp://myserver/myservice.dll?handler=genmyservicewsdl/out:myservice.h

The following command line generates an output file that contains C + + proxy code that accesses the XML webservices described by the WSDL that is obtained from the Results.discomap (which contains a link to a local copy of the. wsdl file):

Copy

Sproxyresults.discomap

CSoapSocketClientT class Description

, refer to HTTP://MSDN.MICROSOFT.COM/ZH-CN/SUBSCRIPTIONS/0YW680WB (vs.80). aspx


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.