S
shaopu
I have created a C++ application to form soap message and post it to
web service through XMLHttp. The program is running fine if the web
service method has no parameter. However it returned "internal server
error" if the web service has some parameter.
My web service is like this:
[WebMethod]
public string HelloWorld(string para)
{
return "Hello World";
}
My C++ code is like below:
Utils.h
#if !defined(XMLHTTPUtilsIncluded)
#define XMLHTTPUtilsIncluded
#define TEMP_SIZE _MAX_PATH // size of short buffer
static _TCHAR szTemp[TEMP_SIZE]; // multipurpose buffer on
stack
static DWORD dwLen; // buffer size
LPCTSTR gszPkgSOAP =
_T("<SOAP-ENV:Envelope "
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'"
" xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
" <SOAP-ENV:Body>"
" <HelloWorld>"
" <para>12</para>"
" </HelloWorld>"
" </SOAP-ENV:Body> "
" </SOAP-ENV:Envelope>"
);
//------------------------------------------------------------------
//
// POSTs a SOAP package to the Web service at
// http://www.xmethods.com/ve2/ViewListing.po?serviceid=8
// to get the current temprature given the ZipCode
//------------------------------------------------------------------
void callSCROMFunction(const _bstr_t &serviceurl,
const _bstr_t &function,
const _bstr_t &loginkey,
const _bstr_t &userid,
const _bstr_t &localid,
const _bstr_t &packageid,
const _bstr_t &path,
const _bstr_t &userdata)
{
try
{
_bstr_t bUrl = serviceurl + function;
// Step 1: Load the SOAP message XML using gszPkgSOAP global variable
IXMLDOMDocument2Ptr pXMLDoc = NULL;
EVAL_HR(pXMLDoc.CreateInstance("Msxml2.DOMDocument.4.0"));
// Load the document synchronously
pXMLDoc->async = false;
// Load the XML document
pXMLDoc->loadXML(gszPkgSOAP);
// Step 2: Update the zipcode node in the SOAP XML message
// Assuming "zipcode" node will always be there
// skipping the step to check if it exists
//pXMLDoc->selectSingleNode("//HelloWorld")->nodeTypedValue =
strZipCode;
// Step 3: Create XMLHTTP and send a POST request to the Web service
IXMLHTTPRequestPtr pXH = NULL;
EVAL_HR (pXH.CreateInstance("Msxml2.XMLHTTP.4.0"));
EVAL_HR (pXH->open("POST", (LPCTSTR)bUrl,
_variant_t(VARIANT_FALSE), _variant_t(""), _variant_t("")));
int iStatus;
_bstr_t bStatusText;
//iStatus = pXH->status;
//bStatusText = pXH->statusText;
EVAL_HR (pXH->setRequestHeader("Content-Type", "text/xml"));
EVAL_HR (pXH->send(pXMLDoc->xml));
// Step 4: If we got back the success response back
// get the value of "return" node from the response SOAP
// message
iStatus = pXH->status;
bStatusText = pXH->statusText;
pXMLDoc = pXH->responseXML;
_bstr_t btmp1 = pXMLDoc->xml;
if (pXH->status== 200)
{// Success
pXMLDoc = pXH->responseXML;
_bstr_t btmp = pXMLDoc->xml;
}
else
{
//*fTemp = (float)-1;
}
}
catch(...)
{// Exception handling
}
}
#endif // !XMLHTTPUtilsIncluded
in the main.cpp, make the following function call:
callSCROMFunction("http://localhost:/LEAD/test/Service1.asmx/",
"HelloWorld", "", "", "", "", "", "");
After calling pXH->send(), pXH->status is 0x000001f4 ("internal server
error")
Can anyone help to find the problem?
Thanks
Shaopu
web service through XMLHttp. The program is running fine if the web
service method has no parameter. However it returned "internal server
error" if the web service has some parameter.
My web service is like this:
[WebMethod]
public string HelloWorld(string para)
{
return "Hello World";
}
My C++ code is like below:
Utils.h
#if !defined(XMLHTTPUtilsIncluded)
#define XMLHTTPUtilsIncluded
#define TEMP_SIZE _MAX_PATH // size of short buffer
static _TCHAR szTemp[TEMP_SIZE]; // multipurpose buffer on
stack
static DWORD dwLen; // buffer size
LPCTSTR gszPkgSOAP =
_T("<SOAP-ENV:Envelope "
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'"
" xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
" <SOAP-ENV:Body>"
" <HelloWorld>"
" <para>12</para>"
" </HelloWorld>"
" </SOAP-ENV:Body> "
" </SOAP-ENV:Envelope>"
);
//------------------------------------------------------------------
//
// POSTs a SOAP package to the Web service at
// http://www.xmethods.com/ve2/ViewListing.po?serviceid=8
// to get the current temprature given the ZipCode
//------------------------------------------------------------------
void callSCROMFunction(const _bstr_t &serviceurl,
const _bstr_t &function,
const _bstr_t &loginkey,
const _bstr_t &userid,
const _bstr_t &localid,
const _bstr_t &packageid,
const _bstr_t &path,
const _bstr_t &userdata)
{
try
{
_bstr_t bUrl = serviceurl + function;
// Step 1: Load the SOAP message XML using gszPkgSOAP global variable
IXMLDOMDocument2Ptr pXMLDoc = NULL;
EVAL_HR(pXMLDoc.CreateInstance("Msxml2.DOMDocument.4.0"));
// Load the document synchronously
pXMLDoc->async = false;
// Load the XML document
pXMLDoc->loadXML(gszPkgSOAP);
// Step 2: Update the zipcode node in the SOAP XML message
// Assuming "zipcode" node will always be there
// skipping the step to check if it exists
//pXMLDoc->selectSingleNode("//HelloWorld")->nodeTypedValue =
strZipCode;
// Step 3: Create XMLHTTP and send a POST request to the Web service
IXMLHTTPRequestPtr pXH = NULL;
EVAL_HR (pXH.CreateInstance("Msxml2.XMLHTTP.4.0"));
EVAL_HR (pXH->open("POST", (LPCTSTR)bUrl,
_variant_t(VARIANT_FALSE), _variant_t(""), _variant_t("")));
int iStatus;
_bstr_t bStatusText;
//iStatus = pXH->status;
//bStatusText = pXH->statusText;
EVAL_HR (pXH->setRequestHeader("Content-Type", "text/xml"));
EVAL_HR (pXH->send(pXMLDoc->xml));
// Step 4: If we got back the success response back
// get the value of "return" node from the response SOAP
// message
iStatus = pXH->status;
bStatusText = pXH->statusText;
pXMLDoc = pXH->responseXML;
_bstr_t btmp1 = pXMLDoc->xml;
if (pXH->status== 200)
{// Success
pXMLDoc = pXH->responseXML;
_bstr_t btmp = pXMLDoc->xml;
}
else
{
//*fTemp = (float)-1;
}
}
catch(...)
{// Exception handling
}
}
#endif // !XMLHTTPUtilsIncluded
in the main.cpp, make the following function call:
callSCROMFunction("http://localhost:/LEAD/test/Service1.asmx/",
"HelloWorld", "", "", "", "", "", "");
After calling pXH->send(), pXH->status is 0x000001f4 ("internal server
error")
Can anyone help to find the problem?
Thanks
Shaopu