By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Calling Webservices from c++ using dot net Framework/Soap tool kit 3.0-Help reqd....

P: n/a
Hi,
I have a requirement to call webservices from my old C++
application.So first I tried with Vc++.net as follows.....There 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.Basically 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::CHPVROOMS v;
VROOMS::VRoomsPartnerAuth AuthInfo;

AuthInfo.AccountName = SysAllocString(L"username");
AuthInfo.Pwd = SysAllocString(L"passwd");

v.VRoomsPartnerAuth11 = 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 HostingLocations { NOHOSTINGAVAILABLE = 0,
EXTERNALHOSTING_LOCATION = 1, INTERNALHOSTING_LOCATION = 2,
INTERNALANDEXTERNALHOSTING = 3, };

struct VRoomsPartnerAuth
{
BSTR AccountName;
BSTR SubAccountName;
BSTR Pwd;
};

template <typename TClient = CSoapSocketClientT<> >
class CHPVROOMST :
public TClient,
public CSoapRootHandler
{
public:

//
// SOAP headers
//

VRoomsPartnerAuth VRoomsPartnerAuth22;
VRoomsPartnerAuth VRoomsPartnerAuth31;
VRoomsPartnerAuth VRoomsPartnerAuth24;
VRoomsPartnerAuth VRoomsPartnerAuth21;
VRoomsPartnerAuth VRoomsPartnerAuth20;
VRoomsPartnerAuth VRoomsPartnerAuth17;
VRoomsPartnerAuth VRoomsPartnerAuth16;
VRoomsPartnerAuth VRoomsPartnerAuth15;
VRoomsPartnerAuth VRoomsPartnerAuth13;
VRoomsPartnerAuth VRoomsPartnerAuth6;
VRoomsPartnerAuth VRoomsPartnerAuth14;
VRoomsPartnerAuth VRoomsPartnerAuth7;
VRoomsPartnerAuth VRoomsPartnerAuth5;
VRoomsPartnerAuth VRoomsPartnerAuth32;
VRoomsPartnerAuth VRoomsPartnerAuth9;
VRoomsPartnerAuth VRoomsPartnerAuth8;
VRoomsPartnerAuth VRoomsPartnerAuth19;
VRoomsPartnerAuth VRoomsPartnerAuth10;
VRoomsPartnerAuth VRoomsPartnerAuth12;
VRoomsPartnerAuth VRoomsPartnerAuth29;
VRoomsPartnerAuth VRoomsPartnerAuth18;
VRoomsPartnerAuth VRoomsPartnerAuth11;
VRoomsPartnerAuth VRoomsPartnerAuth23;
VRoomsPartnerAuth VRoomsPartnerAuth30;
VRoomsPartnerAuth VRoomsPartnerAuth28;

protected:

const _soapmap ** GetFunctionMap();
const _soapmap ** GetHeaderMap();
void * GetHeaderValue();
const wchar_t * GetNamespaceUri();
const char * GetServiceName();
const char * GetNamespaceUriA();
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
VRoomsPartnerAuth like
VRoomsPartnerAuth11 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\Binaries\MSSOAP30.dll" \
exclude("IStream", "ISequentialStream", "_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
using namespace MSSOAPLib30;

void f0()
{
try()
{
ISoapSerializerPtr Serializer,s;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;
// Connect to the service
Connector.CreateInstance(__uuidof(HttpConnector30) );
Connector->Property["EndPointURL"] =
"https://www.websevice.com/service.asmx";
Connector->Connect();

// Begin message for Multiply
Connector->Property["SoapAction"] =
"http://www.websevice.com/websermethod1";
Connector->BeginMessage();

// Create the SoapSerializer
Serializer.CreateInstance(__uuidof(SoapSerializer3 0));

// Connect the serializer to the input stream of the connector
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

// Build the SOAP Message
Serializer->StartEnvelope("","","");

Serializer->StartHeader("");
Serializer->StartElement("VRoomsPartnerAuth","http://webesrvice.com/","","");
Serializer->StartElement("AccountName","","","");
Serializer->WriteString("accname");
Serializer->EndElement();

Serializer->StartElement("SubAccountName","","","");
Serializer->WriteString("subacc name");
Serializer->EndElement();

Serializer->StartElement("Pwd","","","");
Serializer->WriteString("password");
Serializer->EndElement();
Serializer->EndElement();
Serializer->EndHeader();
Serializer->StartBody("");
Serializer->StartElement("websermethod1","http://webservice.com/",
"", "M");
Serializer->StartElement("PartnerRefStr","","","");
Serializer->WriteString("refstring");
Serializer->EndElement();
Serializer->EndElement();

Serializer->EndBody();
Serializer->EndEnvelope();
// Send the message to the web service
Connector->EndMessage();

// Read the response
Reader.CreateInstance(__uuidof(SoapReader30));

// Connect the reader to the output stream of the connector
Reader->Load(_variant_t((IUnknown*)Connector->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(NULL);
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????
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.