VS2008 unmanaged C + + call WCF (WebService) service

Source: Internet
Author: User
Tags wsdl

In Visual Studio 2008 and later, Microsoft stopped the direct WebService reference to unmanaged C + +. However, ATL Server code is already hosted on an open source site, and we can find the source code for ATL Server and compile the Sproxy.exe, which can generate unmanaged proxy classes based on the WSDL file. This proxy class also needs to be combined with some header files to be used together, and this related header file is included in the ATL Server's source code.

1. The first step is to use the Sproxy.exe tool to generate the proxy class. The previous version of VS2008, such as VS2005, itself carries this command, but in the vs2008 version, it has been removed. Need to go to http://atlserver.codeplex.com/download Atl_server source code and compile the Sproxy.exe tool.

1.1 First download the good file atl_server_source_and_headers_9_0_70425_ Alpha.rar extract it, and then go to the folder to copy all the files in the include to the default include folder in vs2008, such as my path: "D:\ProgramFiles\Microsoft Visual Studio 9.0\vc\ Include, it's a good idea to back up your original include folder before copying it.

After 1.2 with "atl_server_source_and_headers_9_0_70425_alpha\source\sproxy\", open "Sproxy.sln" file with vs2008, and make version conversions at the vs2008 prompt.

1.3 Compile run, generate Sproxy.exe file.

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

SPROXY.EXE/WSDL weatherws.wsdl

The WeatherWS.h file is generated in the same directory.

3. Open VS2008, create an MFC project WebService, add the WebServiceDlg.cpp file

#include "WeatherWS.h"

using namespace Weatherws;

Add the following test code to the button click event:

void Cwebservicedlg::onbnclickedbutton1 ()

{

TODO: Add control notification Handler code here

CoInitialize (NULL);

HRESULT hr = S_OK;

cweatherwst<csoapsocketclientt<>>* m_srv = new cweatherwst<csoapsocketclientt<>>;

CComBSTR Citycode = ""; parameter is empty default return weather conditions in Shanghai

CComBSTR userId = "";

CComBSTR * BSTROUT;

int size;

HR =m_srv->getweather (Citycode, UserId, (BSTR * *) &bstrout, &size);

if (FAILED (HR))

{

MessageBox (L "call failed");

}

Else

{

MessageBox (L "Call succeeded");

}

if (m_srv! = NULL)

Delete m_srv;

CoUninitialize ();

}

The above information is compiled from the network, thanks to the original author.

VS2008 unmanaged C + + call WCF (WebService) service

Related Article

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.