在Pwin97/Win2000 Professional下运行通过。
#include <windows.h>
#include <easysoap/SOAP.h>
USING_EASYSOAP_NAMESPACE
//
// The namespace for the methods we're calling. This
// is the same namespace defined in calchandler.h.
int main(int argc, const char *argv[])
{
int iRet = 0;
unsigned short* strWideChar = NULL;
char* strANSIReturn = NULL;
try
{
const char * strUrl = "http://169.254.45.130/WS/Service1.asmx?op=HelloWorld";
const char * strNameSpace = "http://tempuri.org/";
const char * strSOAPAction = "http://tempuri.org/HelloWorld";
const char * strMethodName = "HelloWorld";
SOAPString url(strUrl);
SOAPUrl endpoint(url);
SOAPProxy proxy(endpoint);
SOAPMethod method(strMethodName, strNameSpace, strSOAPAction);
SOAPString inputValue;
char str[5] = "中文";
int iLenWideChar = MultiByteToWideChar(0, 0, const_cast<char *>(str), sizeof(str), NULL, 0);
strWideChar = new unsigned short[iLenWideChar];
if(NULL == strWideChar)
{
goto Exit;
}
int iLenRet = MultiByteToWideChar(0, 0, const_cast<char *>(str), sizeof(str), strWideChar, iLenWideChar);
inputValue.Append(strWideChar);
method.AddParameter("a") << 1;
method.AddParameter("b") << inputValue;
const SOAPResponse& response = proxy.Execute(method);
SOAPString strRet = response.GetReturnValue().GetString();
//get return value (UTF-8 encoding)
char * strReturn = strRet.Str();
unsigned int iLenReturn = sp_strlen(strReturn);
SOAPArray<unsigned short> UTF8Return(iLenReturn);
char * iterator = strReturn;
//convert UTF-8 to WideChar
for(unsigned int i=0; iterator <= (strReturn+iLenReturn) && i<iLenReturn; ++i)
{
sp_UTF8_UCS(iterator,UTF8Return[i]);
}
//UTF-8 to UTF16
int iLenANSIReturn = WideCharToMultiByte(0, 0, UTF8Return, -1, NULL, 0, NULL, NULL);
strANSIReturn = new char[iLenANSIReturn];
if(NULL == strANSIReturn)
{
goto Exit;
}
WideCharToMultiByte(0, 0, UTF8Return, -1, strANSIReturn, iLenANSIReturn, NULL, NULL);
printf("ANSI:%s\n", strANSIReturn);
getchar();
}
catch (SOAPException& ex)
{
printf("Caught SOAP exception: %s\n", ex.What().Str());
iRet = 1;
}
Exit:
if(NULL != strWideChar)
{
delete [] strWideChar;
strWideChar = NULL;
}
if(NULL != strANSIReturn)
{
delete [] strANSIReturn;
strANSIReturn = NULL;
}
return iRet;
}