Click here to Skip to main content
6,595,854 members and growing! (18,700 online)
Email Password   helpLost your password?
Languages » XML » Messaging     Intermediate License: The Code Project Open License (CPOL)

C++ SOAP client for MS SOAP Toolkit 1.0 using wire transfer technique

By Catalin Hatmanu

C++ SOAP client for December 2000 release of MS SOAP Toolkit 1.0 using wire transfer technique
XML, VC6Win2K, ATL, Dev
Posted:26 Jan 2001
Updated:7 Feb 2001
Views:70,151
Bookmarked:15 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
21 votes for this article.
Popularity: 5.10 Rating: 3.86 out of 5

1

2

3
1 vote, 33.3%
4
2 votes, 66.7%
5
  • Download source files - 2 Kb
  • Download demo project - 62 Kb
  • Requirements

  • SOAP Toolkit Version 1.0 - December 2000 Release
  • Microsoft XML Parser (Part of IE5 or later)
  • Introduction

    In July 2000, Microsoft released the first version of the SOAP Toolkit for Visual Studio 6.0. In September 2000 the Beta 1 of the SOAP Toolkit Version 1.0 was release. In my opinion the most remarkable feature that was added is the SSL support. The most recent, non beta version is the version from December 2000 with bug fixes and small changes in the exposed interfaces. The purpose of this article is to demonstrate the wire transfer technique using a C++ client and ATL. Many thanks to Peter Santos.

    About sample

    MS provided, for testing purposes, the web service. The web service description can be found at the following link. The sample use this web service and demonstrates the execution of GetStockQuote method exposed by this web service. The sample contain two methods Connect and GetStockMethod.

    Connect method

    This is the method for obtaining the service description and URI listener from the web service. These are two strings (BSTRs) that we will keep for using in GetStockMethod

    	long            nSuccess, item = 0;
    	CComVariant     varTemp;
    
    	ROPE::ISOAPPackagerPtr          packer;
    	CComPtr<IUnknown>               pIUnknown;
    	ROPE::IServiceDescriptorsPtr    pIServiceDescriptors;
    	ROPE::ISDEndPointInfoPtr        pISDEndPointInfo;
    	USES_CONVERSION;
    
    	try
    	{
    		
    		HRESULT hr = packer.CreateInstance( ROPE::CLSID_SOAPPackager );
    		
    		//load service description from this web service
    
    		hr = packer->LoadServicesDescription(ROPE::icURI, 
    							bstrLocation, NULL, &nSuccess);
    		if( nSuccess != 1 )
    			throw E_FAIL;
    
    		//get service descriptors
    
    		hr = packer->get_GetServiceDescriptors(ROPE::icENDPOINTINFO, &varTemp);
    
    		pIUnknown.Attach( varTemp.pdispVal );
    		pIUnknown.QueryInterface( &pIServiceDescriptors );
    		
    		//get first descriptor on the list
    
    		VariantInit(&varTemp);
    		hr = pIServiceDescriptors->get_Item(variant_t(item),&varTemp);
    		pIUnknown.Detach();
    
    		//get the endpoint(URI address) a.e. where the SOAP message will be sent
    
    		pIUnknown.Attach( varTemp.pdispVal );
    		hr = pIUnknown.QueryInterface( &pISDEndPointInfo );
    		hr = pISDEndPointInfo->get_URI(&URI_LISTENER);
    		
    		//get the service description
    
    		hr = packer->get_ServicesDescription(&bstrSrvDesc);
    	}
    	catch(...)
    	{
    		std::cout << "Connection failure ! "<< std::endl;
    		return false;
    	}
    	std::cout << "Connection successfull "<< std::endl;
    	return true;

    GetStockMethod

    This is the method for calling the exposed GetStockPrice method from the web service. After the creation of a new SOAPPackager object and the loading of the service description from the string obtained from the Connect method, the payload will be created and posted (using a new WireTransfer object)to the web service and the result will be displayed

    	long		nSuccess;
    	CComBSTR	bstrRequestStruct, bstrRequestPayload, bstrResponsePayload;
    	CComVAriant varPrice;
    	
    	ROPE::ISOAPPackagerPtr packer;
    	ROPE::IWireTransferPtr wireTrans;
    
    	USES_CONVERSION;
    
    	try
    	{
    		HRESULT hr = packer.CreateInstance( ROPE::CLSID_SOAPPackager );
    
    		//load service description using the string from previous Connect method call
    
    		hr = packer->LoadServicesDescription(ROPE::icSTRING, 
    							bstrSrvDesc, NULL, &nSuccess);
    		if( nSuccess != 1 )
    			throw E_FAIL;
    		
    		//seek in the service description 
    
    		//the method structure a.e. what we need to call this method
    
    		hr = packer->GetMethodStruct(CComBSTR("GetStockQuote"), ROPE::icINPUT, &bstrRequestStruct);
    		
    		// set method name 
    
    		hr = packer->SetPayloadData(ROPE::icREQUEST, CComBSTR(""), CComBSTR("GetStockQuote"), bstrRequestStruct); 
    
    		//set method parameters
    
    		hr = packer->SetParameter(  ROPE::icREQUEST, CComBSTR("Symbol"), CComVariant("MSFT") );
    		hr = packer->SetParameter(  ROPE::icREQUEST, CComBSTR("description"), CComVariant("any company") );
    
    		//get the data that will be sended to web server( payload ) 
    
    		hr = packer->GetPayload( ROPE::icREQUEST, &bstrRequestPayload);
    
    		std::cout <<  W2A(bstrRequestPayload) << std::endl << std::endl;
    		
    		//post the payload
    
    		wireTrans.CreateInstance( ROPE::CLSID_WireTransfer);
    		hr = wireTrans->AddStdSOAPHeaders(URI_LISTENER,CComBSTR("GetStockQuote"),bstrRequestPayload.Length());
    		hr = wireTrans->PostDataToURI(URI_LISTENER, bstrRequestPayload, &bstrResponsePayload);
    
    		std::cout <<  W2A(bstrResponsePayload) << std::endl << std::endl;
    
    		//this is the response from service 
    
    		hr = packer->SetPayload( ROPE::icRESPONSE, bstrResponsePayload);
    		
    		//get return value
    
    		hr = packer->GetParameter( ROPE::icRESPONSE, CComBSTR("result"), &varPrice);
    		std::cout << W2A(varPrice.bstrVal) << std::endl;
    	}
    	catch(...)
    	{
    		std::cout << "Something wrong happened !" << std::endl<< std::endl;
    	}

    Conclusions

    I hope you will find this approach useful.

    License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    About the Author

    Catalin Hatmanu


    Member
    Programmer since 1994 using C#/C++/C/VB/VB.Net/SQL Server. Experience with ASP.Net,SOAP,COM/DCOM, ATL
    Occupation: Software Developer (Senior)
    Location: Canada Canada

    Other popular XML articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
    GeneralSOAP response is ? PinmemberILoveMJ3:55 18 Dec '06  
    GeneralHELP ME!!!why toolkit3.0 generate these bad XML for me? Pinmembergxulg20:08 16 Jan '05  
    Generaljava and SOAP Pinmemberramzi1:33 17 May '01  
    GeneralSOAP+java Pinmemberramzi6:21 16 May '01  
    GeneralRe: SOAP+java PinmemberCatalin Hatmanu7:49 16 May '01  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 7 Feb 2001
    Editor: Erik Thompson
    Copyright 2001 by Catalin Hatmanu
    Everything else Copyright © CodeProject, 1999-2009
    Web18 | Advertise on the Code Project