Gsoap

举报
清雨小竹 发表于 2022/09/25 02:10:45 2022/09/25
【摘要】 1.create 命令 wsdl2h -o a.h   up.WSDL soapcpp2.exe  -C -x a.h 2.添加文件 soapTestSoap12Proxy.h soapTestSoapProx...
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;

}
}

文章来源: zzzili.blog.csdn.net,作者:清雨小竹,版权归原作者所有,如需转载,请联系作者。

原文链接:zzzili.blog.csdn.net/article/details/8265518

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。