1.create 命令
wsdl2h -o a.h up.WSDL soapcpp2.exe -C -x a.h
2.添加文件
soapTestSoap12Proxy.h soapTestSoapProxy.h soapH.h soapStub.h stdsoap2.h soapClientLib.cpp soapC.cpp soapClient.cpp stdsoap2.cpp 3.CSoap.h /*/ Gsoap处理类 */ #ifndef _CSOAP #define _CSOAP /// #pragma once #include "stdafx.h" #include "soapH.h" #include "CRegister.h" using namespace std; class CSOAP { private: struct soap m_soap; SOAP_ENV__Header header; public: CSOAP(); ~CSOAP(); bool InitSoap(); }; #endif CSoap.cpp #pragma once #include "StdAfx.h" #include "CSoap.h" #include "string" #include "FaceAttendanceCoreSoap.nsmap" #include <afxwin.h> #pragma warning(disable: 4996) static std::string headerPass="Lucky"; static std::string headerName="Lucky"; wstring UTF8ToUnicode( const string& str ){ int len = 0; len = str.length(); int unicodeLen = ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, NULL, 0 ); wchar_t * pUnicode; pUnicode = new wchar_t[unicodeLen+1]; memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen ); wstring rt; rt = ( wchar_t* )pUnicode; delete pUnicode; return rt; } string UnicodeToANSI( const wstring& str ){ char* pElementText; int iTextLen; iTextLen = WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, NULL, 0,NULL, NULL ); pElementText = new char[iTextLen + 1]; memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) ); ::WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL ); string strText; strText = pElementText; delete[] pElementText; return strText;} wstring ANSIToUnicode( const string& str ){ int len = 0; len = str.length(); int unicodeLen = ::MultiByteToWideChar( CP_ACP, 0, str.c_str(), -1, NULL, 0 ); wchar_t * pUnicode; pUnicode = new wchar_t[unicodeLen+1]; memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); ::MultiByteToWideChar( CP_ACP, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen ); wstring rt; rt = ( wchar_t* )pUnicode; delete pUnicode; return rt; } string UnicodeToUTF8( const wstring& str ){ char* pElementText; int iTextLen; iTextLen = WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, NULL, 0, NULL, NULL ); pElementText = new char[iTextLen + 1]; memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) ); ::WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL ); string strText; strText = pElementText; delete[] pElementText; return strText;} CSOAP::CSOAP() { InitSoap(); } CSOAP::~CSOAP() { soap_destroy(&m_soap); soap_end(&m_soap); soap_done(&m_soap); } bool CSOAP::InitSoap() { soap_init(&m_soap); soap_set_mode(&m_soap,SOAP_C_UTFSTRING); m_soap.mode|=SOAP_C_UTFSTRING; header.ns1__MySoapHeader_=new ns1__MySoapHeader; header.ns1__MySoapHeader_->PassWord=&headerPass; header.ns1__MySoapHeader_->UserName=&headerName; m_soap.header=&header; return true; } bool CSOAP::EnLogin(CString name,CString pass,CString &tip)//管理员登陆 { _ns1__UserLogin login; _ns1__UserLoginResponse loginResponse; string loginPass=pass; string loginName=name; login.PassWord=&loginPass; login.UserName=&loginName; m_soap.header=&header; if(SOAP_OK==soap_call___ns2__UserLogin(&m_soap,NULL,NULL,&login,&loginResponse)) { Sleep(500); tip=DecodeUtf8(loginResponse.UserLoginResult->ResultContent->c_str()); if(loginResponse.UserLoginResult->ErrorCode==0) return true; else return false; } else { tip=_T("网络连接失败"); //tip.Format(_T("%s"),*soap_faultstring(&m_soap)); return false; } }