Hi,
I have a requirement to call webservices from my old C++
application.So first I tried with Vc++.net as follows.....The re are 2
approach Dotnet frame work and soaptoolkit 3.0
I am not able to interact with webservice thru c++.I think ther is a
bug in MS implementation for c++ to interact with webservice because I
am able to connect to the same webservice thru C# as well as vb.net.
I tried the following approaches
Approach I:Using Dot net framework + ATL:
=============== =============== ============
1)I opened vc++.net and select Vc++ proj-> console app with ATL
support and add the webservice asmx file as webreferences.. I tried to
interact with the webservices.Bas ically it has an authentication
mechanism that you have to send ur username and passwd thru the soap
header.So the code fragment i wrote is as follows..
#include "stdafx.h"
using namespace std;
void f0(){
VROOMS::CHPVROO MS v;
VROOMS::VRoomsP artnerAuth AuthInfo;
AuthInfo.Accoun tName = SysAllocString( L"username") ;
AuthInfo.Pwd = SysAllocString( L"passwd");
v.VRoomsPartner Auth11 = AuthInfo;
int res = -1;
BSTR prs = SysAllocString( L"username") ;
HRESULT hr = v.webservice method1(prs, &res);
}
int _tmain(int argc, _TCHAR* argv[])
{
OleInitialize(0 );
f0();
OleUninitialize ();
return 0;
}Basically it is not authenticating and Iam getting E_FAIL. The proxy
class created by Vc++ 7 is as follows (code fragment)
=============== =============== =============== =============== =============== ===
#include <atlsoap.h>
namespace HPVROOMS
{
enum HostingOptions { NORECORDING = 0, EXTERNALHOSTING _ONLY = 1,
INTERNALHOSTING _ONLY = 2, DOWNLOAD_ONLY = 3, EXTERNALHOSTING _DOWNLOAD
= 4, INTERNALHOSTING _DOWNLOAD = 5, };
enum HostingLocation s { NOHOSTINGAVAILA BLE = 0,
EXTERNALHOSTING _LOCATION = 1, INTERNALHOSTING _LOCATION = 2,
INTERNALANDEXTE RNALHOSTING = 3, };
struct VRoomsPartnerAu th
{
BSTR AccountName;
BSTR SubAccountName;
BSTR Pwd;
};
template <typename TClient = CSoapSocketClie ntT<> >
class CHPVROOMST :
public TClient,
public CSoapRootHandle r
{
public:
//
// SOAP headers
//
VRoomsPartnerAu th VRoomsPartnerAu th22;
VRoomsPartnerAu th VRoomsPartnerAu th31;
VRoomsPartnerAu th VRoomsPartnerAu th24;
VRoomsPartnerAu th VRoomsPartnerAu th21;
VRoomsPartnerAu th VRoomsPartnerAu th20;
VRoomsPartnerAu th VRoomsPartnerAu th17;
VRoomsPartnerAu th VRoomsPartnerAu th16;
VRoomsPartnerAu th VRoomsPartnerAu th15;
VRoomsPartnerAu th VRoomsPartnerAu th13;
VRoomsPartnerAu th VRoomsPartnerAu th6;
VRoomsPartnerAu th VRoomsPartnerAu th14;
VRoomsPartnerAu th VRoomsPartnerAu th7;
VRoomsPartnerAu th VRoomsPartnerAu th5;
VRoomsPartnerAu th VRoomsPartnerAu th32;
VRoomsPartnerAu th VRoomsPartnerAu th9;
VRoomsPartnerAu th VRoomsPartnerAu th8;
VRoomsPartnerAu th VRoomsPartnerAu th19;
VRoomsPartnerAu th VRoomsPartnerAu th10;
VRoomsPartnerAu th VRoomsPartnerAu th12;
VRoomsPartnerAu th VRoomsPartnerAu th29;
VRoomsPartnerAu th VRoomsPartnerAu th18;
VRoomsPartnerAu th VRoomsPartnerAu th11;
VRoomsPartnerAu th VRoomsPartnerAu th23;
VRoomsPartnerAu th VRoomsPartnerAu th30;
VRoomsPartnerAu th VRoomsPartnerAu th28;
protected:
const _soapmap ** GetFunctionMap( );
const _soapmap ** GetHeaderMap();
void * GetHeaderValue( );
const wchar_t * GetNamespaceUri ();
const char * GetServiceName( );
const char * GetNamespaceUri A();
HRESULT CallFunction(
void *pvParam,
const wchar_t *wszLocalName, int cchLocalName,
size_t nItem);
HRESULT GetClientReader (ISAXXMLReader **ppReader);
public:
HRESULT webmethod1(
BSTR RefStr,
int* Result
);
=============== =============== =============== =============== =============== ====
The proxy class generated creates too many variables for
VRoomsPartnerAu th like
VRoomsPartnerAu th11 etc.. but this is not happening with C# or VB.net
and only one class is generated and Iam able to interact with web
service successfully in c# or vb.net. Here only this problem comes.
So i moved 2 second approach using Soap tool kit 3.0
Approach -II:Using Soap toolkit 3.0 in VC6/7:
=============== =============== ==============
include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#import "msxml3.dll "
using namespace MSXML2;
#import "C:\Program Files\Common Files\MSSoap\Bi naries\MSSOAP30 .dll" \
exclude("IStrea m", "ISequentialStr eam", "_LARGE_INTEGER ", \
"_ULARGE_INTEGE R", "tagSTATSTG ", "_FILETIME" )
using namespace MSSOAPLib30;
void f0()
{
try()
{
ISoapSerializer Ptr Serializer,s;
ISoapReaderPtr Reader;
ISoapConnectorP tr Connector;
// Connect to the service
Connector.Creat eInstance(__uui dof(HttpConnect or30));
Connector->Property["EndPointUR L"] =
"https://www.websevice.c om/service.asmx";
Connector->Connect();
// Begin message for Multiply
Connector->Property["SoapAction "] =
"http://www.websevice.c om/websermethod1";
Connector->BeginMessage() ;
// Create the SoapSerializer
Serializer.Crea teInstance(__uu idof(SoapSerial izer30));
// Connect the serializer to the input stream of the connector
Serializer->Init(_variant_ t((IUnknown*)Co nnector->InputStream) );
// Build the SOAP Message
Serializer->StartEnvelope( "","","");
Serializer->StartHeader("" );
Serializer->StartElement(" VRoomsPartnerAu th","http://webesrvice.com/","","");
Serializer->StartElement(" AccountName","" ,"","");
Serializer->WriteString("a ccname");
Serializer->EndElement() ;
Serializer->StartElement(" SubAccountName" ,"","","");
Serializer->WriteString("s ubacc name");
Serializer->EndElement() ;
Serializer->StartElement(" Pwd","","","") ;
Serializer->WriteString("p assword");
Serializer->EndElement() ;
Serializer->EndElement() ;
Serializer->EndHeader();
Serializer->StartBody("" );
Serializer->StartElement(" websermethod1", "http://webservice.com/",
"", "M");
Serializer->StartElement(" PartnerRefStr", "","","");
Serializer->WriteString("r efstring");
Serializer->EndElement() ;
Serializer->EndElement() ;
Serializer->EndBody();
Serializer->EndEnvelope( );
// Send the message to the web service
Connector->EndMessage() ;
// Read the response
Reader.CreateIn stance(__uuidof (SoapReader30)) ;
// Connect the reader to the output stream of the connector
Reader->Load(_variant_ t((IUnknown*)Co nnector->OutputStream," "),
"");
// Display the result
printf("Answer for websermethod: %s\n", (const char
*)Reader->RpcResult->text);
}
catch(com error e)
{
printf("The error desc is %s\n", e.description() );
}
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NU LL);
f0();
CoUninitialize( );
return 0;
}
=============== =============== =============== =============== =============== =====
Here Iam getting "Connection Timed out" error here. I found out from
MSDN that there is a bug with soap toolkit 2.0
FIX: SOAP SDK: ConnectTimeout Does Not Apply to Dotted IP Address
The url is
http://support.microsoft.com/default...s%3BQ311275#ap
but it is told that it is fixed in MS soap tool kit 3.0.but i am
getting the same kind of error using tool kit 3.0 also.
Also this problem is clearly with problems in MS implementation for
c++ to interact with webservice because I am able to connect to the
same webservice thru C# as well as vb.net.
So any takers pls????