【小记备忘】之Winnet调用webservice【2013.12.23】
欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611
#include "stdafx.h" #include <windows.h> #include <wininet.h> //#import "Wininet.lib" static TCHAR* g_lpszSOAPRequest = _T("<soap:Envelope ") _T("xmlns:n='urn:xmethods-Temperature' ") _T("xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' ") _T("xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' ") _T("xmlns:xs='http://www.w3.org/2001/XMLSchema' ") _T("xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> ") _T("<soap:Body soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'> ") _T(" <n:getTemp> ") _T(" <zipcode xsi:type='xs:string'>98007</zipcode> ") _T(" </n:getTemp> ") _T("</soap:Body> ") _T("</soap:Envelope>"); #define CHUNK_SIZE 2048 int CallWebService(); int _tmain(int argc,_TCHAR* argv[]) { CallWebService(); return 0; } int CallWebService() { HINTERNET hSession = ::Internetopen(_T("SoapTrans"),INTERNET_OPEN_TYPE_PRECONfig,_T(""),INTERNET_INVALID_PORT_NUMBER,0); if(hSession == NULL) { return 0; } HINTERNET hConnect = ::InternetConnect(hSession,_T("localhost"),NULL,INTERNET_SERVICE_HTTP,0); if(hConnect == NULL) { ::InternetCloseHandle(hSession); return 0; } HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,_T("POST"),_T("/WebService....."),HTTP_VERSION,INTERNET_FLAG_DONT_CACHE,0); if(hHttpFile == NULL) { ::InternetCloseHandle(hConnect); ::InternetCloseHandle(hSession); return 0; } BOOL bSendRequest = ::HttpSendRequest(hHttpFile,-1,g_lpszSOAPRequest,strlen(g_lpszSOAPRequest)); if(bSendRequest) { { char achQueryBuf[16]; DWORD dwFileSize; DWORD dwQueryBufLen = sizeof(achQueryBuf); BOOL bQuery = ::HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH,achQueryBuf,&dwQueryBufLen,NULL); if(bQuery) { dwFileSize = (DWORD)atol(achQueryBuf); char* response = new char[dwFileSize]; DWORD dwLength; BOOL bGet = ::InternetReadFile(hHttpFile,response,dwFileSize,&dwLength); printf(response); } } ::InternetCloseHandle(hHttpFile); ::InternetCloseHandle(hConnect); ::InternetCloseHandle(hSession); } }
158427611
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。