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

How to call .net WebService from MFC dll written using .net 2003 I

P: n/a
Hi,

I have a vb.net webservice which takes XMLDocument as a parameter and
returns bool. Signature of the method is some thing like this
AddXmlEmpDetails(xmlEmp as XMLDocument) as Boolean. I am able to call this
method from vb.net desktop client and add a record to the database(this I
used to test if there is any problem in the webservice).

My main requirement is to create a C++(native dll) wrapper what is
recognized by a non microsoft application.

For my testing purpose I am doing the following.

I created a MFC dll (wrapper) using .net 2003 IDE. I created a win32
client using .net 2003 IDE.

I am able to use other webmethods in my wrapper like GetXmlEmpdetails
which returns an XMLDocument.

I am facing a problem when I am calling AddXmlEmpDetails(webmethod) in
my wrapper. It say error '500' basically resource not found. I did a debug
and found out that the xml content that I am sending to the webMethod in BSTR
formate is getting changed. For example xml content that i am passing is
like this
[

<Employee><EmployeeDetails><EmpID>E116</EmpID><EmpName>Ram</EmpName><EmpAge>35</EmpAge><EmpAddress>Mumbai</EmpAddress></EmployeeDetails></Employee>

]

internally when the soap body is getting built, the content gets changed to
[
<Employee><EmployeeDetails><EmpID>E116</EmpID><EmpName>Ram</EmpName><EmpAge>35</EmpAge><EmpAddress>Mumbai</EmpAddress></EmployeeDetails></Employee>

]

because of which I show an error saying invalid node etc.,

Following is what I have code

I have added an com reference for MSXML2.dll

######################################
[CODE 1
bool CEmpInfoWrapperApp::AddEmpDetailsWrapper(char chrEmpID[11],char
chrEmpName[26],int intEmpAge,char chrEmpAddress[51])
{
CEmpInfo *webEmpInfoClass;
HRESULT hr;

webEmpInfoClass =new CEmpInfo();
hr=::CoInitialize(NULL);
bool bFunctionStatus;
bFunctionStatus=false;

CComPtr <IXMLDOMDocument> EmpXmlDoc;
hr = EmpXmlDoc.CoCreateInstance(__uuidof(DOMDocument));

bFunctionStatus = true;
//GenerateEmpXml is a user defined function which is also
pasted below
bFunctionStatus =
GenerateEmpXml(chrEmpID,chrEmpName,intEmpAge,chrEm pAddress,EmpXmlDoc);

if (bFunctionStatus == false)
{
delete(webEmpInfoClass);
CoUninitialize();
return bFunctionStatus;
}

hr=EmpXmlDoc->save(CComVariant("C:\\temp\\beforeadd.xml"));

BSTR bstrEmpName;
_bstr_t btEmpName;

EmpXmlDoc->get_xml(&bstrEmpName);

bFunctionStatus=false;

hr=webEmpInfoClass->AddXmlEmpDetails(bstrEmpName,&bFunctionStatus);
int errorcode=HRESULT_CODE(hr);
if (SUCCEEDED(hr))
{
delete(webEmpInfoClass);
CoUninitialize();
return bFunctionStatus;
}
else
{
delete(webEmpInfoClass);
CoUninitialize();
return bFunctionStatus;
}

}

END OF CODE1]################################

##########################################
[Code 2

bool CEmpInfoWrapperApp::GenerateEmpXml(char chrEmpID[11],char
chrEmpName[26],int intEmpAge,char chrEmpAddress[51],CComPtr <IXMLDOMDocument>
&Root)
{
HRESULT hr1;
hr1=::CoInitialize(NULL);

//CComPtr <IXMLDOMDocument> Root;
CComPtr<IXMLDOMNode> node;
CComPtr<IXMLDOMNode> OddNodeAddress;
CComPtr<IXMLDOMNode> EvenNodeAddress;
CComPtr <IXMLDOMElement> docElement;
//new
CComPtr <IXMLDOMProcessingInstruction> xmlPrsInst;
_bstr_t btTarget,btData;
btTarget = "xml";
btData = "version=\"1.0\"";
hr1 =
Root->createProcessingInstruction(btTarget.Detach(),btD ata.Detach(),&xmlPrsInst);
hr1 = Root->appendChild(xmlPrsInst,&EvenNodeAddress);
xmlPrsInst.Release();
EvenNodeAddress.Release();
//end of new
//RootElement
hr1 =
Root->createNode(CComVariant(NODE_ELEMENT),CComBSTR("Em ployee"),NULL,&node);
hr1 = Root->appendChild(node,&OddNodeAddress);
node.Release();


//ParentElement
hr1 =
Root->createNode(CComVariant(NODE_ELEMENT),CComBSTR("Em ployeeDetails"),NULL,&node);
hr1 = OddNodeAddress->appendChild(node,&EvenNodeAddress);
node.Release();
OddNodeAddress.Release();

//First ChildElement
hr1 =
Root->createNode(CComVariant(NODE_ELEMENT),CComBSTR("Em pID"),NULL,&node);
node->put_text(CComBSTR(chrEmpID));
hr1 = EvenNodeAddress->appendChild(node,&OddNodeAddress);
node.Release();
OddNodeAddress.Release();
//Second ChildElement
hr1 =
Root->createNode(CComVariant(NODE_ELEMENT),CComBSTR("Em pName"),NULL,&node);
node->put_text(CComBSTR(chrEmpName));
hr1 = EvenNodeAddress->appendChild(node,&OddNodeAddress);
node.Release();
OddNodeAddress.Release();

//Third ChildElement
hr1 =
Root->createNode(CComVariant(NODE_ELEMENT),CComBSTR("Em pAge"),NULL,&node);
char strEmpAge[10];

itoa(intEmpAge,strEmpAge,10);
node->put_text(CComBSTR(strEmpAge));
hr1 = EvenNodeAddress->appendChild(node,&OddNodeAddress);
node.Release();
OddNodeAddress.Release();

//Forth ChildElement
hr1 =
Root->createNode(CComVariant(NODE_ELEMENT),CComBSTR("Em pAddress"),NULL,&node);
node->put_text(CComBSTR(chrEmpAddress));
hr1 = EvenNodeAddress->appendChild(node,&OddNodeAddress);
node.Release();
OddNodeAddress.Release();

hr1=Root->save(CComVariant("C:\\temp\\vc.xml"));
//Root.Release();
node.Release();
OddNodeAddress.Release();
EvenNodeAddress.Release();
CoUninitialize();

//bFunctionStatus = true;
//return Root;
return true;
}
END OF CODE 2]################################
I am unable to send data from my C++ application to my webservice
which accepts data in xmldocument form.

Any help or suggesting in this regards? you could also reply to me
on my mail address: ag***@hotmail.com

Dec 28 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.