mfc call c# webservice method

#include "stdafx.h"
#include "HttpMethod.h"
#import "msxml.dll"
#include "msxml.h"

using namespace MSXML;
using namespace std;
void HttpA()
{
 LPCWSTR agentName = _TEXT("CppBSHttp");

 HINTERNET hInternetAgent = InternetOpen(agentName, LOCAL_INTERNET_ACCESS, NULL, 0, 0);
 if(!hInternetAgent)
 {
  return;
 }
 HINTERNET hInternetConnection = InternetConnect(hInternetAgent, _TEXT("localhost"), 12259, NULL, NULL, INTERNET_SERVICE_HTTP, NULL, NULL);
 if(!hInternetConnection)
 {
  return;
 }

 char* szAccept[] = {"*/*", NULL};

 HINTERNET hInternetRequest = HttpOpenRequest(hInternetConnection, _TEXT("POST"), _TEXT("CBSLogin.ashx"),
  NULL, NULL, (LPCWSTR*)szAccept, 0, 0);

 LPCWSTR headerCon = _TEXT("Content-Type: application/x-www-form-urlencoded");
 LPCWSTR formCon = _TEXT("userName=你好&userPsw=1");

 LPSTR sendFormCon = NULL;
 sendFormCon = (LPSTR)malloc(wcslen(formCon) * 6);
 memset(sendFormCon, 0, wcslen(formCon) * 6);

 WideCharToMultiByte(CP_UTF8, 0, formCon, -1, sendFormCon, wcslen(formCon) * 6, NULL, NULL );
 
 //BOOL bRsl = HttpSendRequest(hInternetRequest, headerCon, wcslen(headerCon), (LPVOID)formCon, wcslen(formCon));
 int lenth = strlen(sendFormCon);
 BOOL bRsl = HttpSendRequest(hInternetRequest, headerCon, wcslen(headerCon), (LPVOID)sendFormCon , strlen(sendFormCon));
 free(sendFormCon);

 char rslBuffer[4096];
 DWORD readSize = 0;
 bRsl = InternetReadFile(hInternetRequest, rslBuffer, 4000, &readSize);
 
 LPWSTR  lp = NULL;
 
 lp = (LPWSTR)malloc(readSize * 2);
 memset(lp, 0, readSize * 2);

 MultiByteToWideChar(CP_UTF8, 0, rslBuffer, readSize, lp, readSize * 2);

 ExplainXml(lp);
 free(lp);


 InternetCloseHandle(hInternetRequest);
 InternetCloseHandle(hInternetConnection);
 InternetCloseHandle(hInternetAgent);
}

void ExplainXml(LPCTSTR xmlCon)
{
 MSXML::IXMLDOMDocumentPtr pXmlDoc;
 MSXML::IXMLDOMElementPtr pXmlRoot;
 CoInitialize(NULL);
 HRESULT hr = pXmlDoc.CreateInstance(__uuidof(MSXML::DOMDocument));
 if(!SUCCEEDED(hr))
 {
  return;
 }
 pXmlDoc->loadXML((_bstr_t)xmlCon);
 pXmlRoot = pXmlDoc->documentElement;
 BSTR aSessionID = pXmlRoot->getAttribute((_bstr_t)"SessionID").bstrVal;
 _bstr_t strTemp;
 strTemp.Attach(aSessionID);
 char* sessionID = (char *)strTemp;
 
 BSTR eResult;
 pXmlRoot->get_text(&eResult);
 _bstr_t strTemp2;
 strTemp2.Attach(eResult);
 char* boolResult = (char *)strTemp2;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值