上传log
//相应头文件
#include "soapWebServiceSoapProxy.h"
#include "WebServiceSoap.nsmap"
上传代码
BOOL CSmtpManagerApp::SendLogToServer()
{
int i=0;
WebServiceSoapProxy service;
std::string result;
CString loggerFileName=g_config_info.GetLoggerFileNameToday();
CString loggerFilePathToday=g_config_info.GetLoggerFilePathToday();
//loggerFileName:CString->wchar_t.
char *wchar_loggerFileName=new char[loggerFileName.GetLength()*2];
memset(wchar_loggerFileName,0,loggerFileName.GetLength()*2);
WideCharToMultiByte(CP_ACP,0,
loggerFileName.GetBuffer(loggerFileName.GetLength()),-1,
wchar_loggerFileName,loggerFileName.GetLength(),
NULL,NULL);
//loggerFilePathToday:CString->wchar_t.
char *wchar_loggerFilePathToday=new char[loggerFilePathToday.GetLength()*2];
memset(wchar_loggerFilePathToday,0,loggerFilePathToday.GetLength()*2);
WideCharToMultiByte(CP_ACP,0,
loggerFilePathToday.GetBuffer(loggerFilePathToday.GetLength()),-1,
wchar_loggerFilePathToday,loggerFilePathToday.GetLength(),
NULL,NULL);
_ns1__GetFileNew *ns1__GetFileNew=new _ns1__GetFileNew;
_ns1__GetFileNewResponse *ns1__GetFileNewResponse=new _ns1__GetFileNewResponse;
string str_logData=GetLogData(wchar_loggerFilePathToday);
string str_loggerFileName(wchar_loggerFileName);//loggerFileName:wchar_t->string
ns1__GetFileNew->name=&str_loggerFileName;
ns1__GetFileNew->logData=&str_logData;
if (!service.GetFileNew(ns1__GetFileNew,ns1__GetFileNewResponse)== SOAP_OK)
{
return FALSE;
}
return TRUE;
}
string CSmtpManagerApp::GetLogData(char* path)
{
FILE *pFile=fopen(path,"rb");
fseek(pFile,0,SEEK_END);
int length=ftell(pFile);
fseek(pFile,4,SEEK_SET);//4:the begin of logfile
wchar_t *wchar_t_logData=new wchar_t[length*sizeof(wchar_t)];
memset(wchar_t_logData,0,length*sizeof(wchar_t));
fread(wchar_t_logData,sizeof(wchar_t),length*sizeof(wchar_t),pFile);
fclose(pFile);
string strlogData(ws2s(wchar_t_logData));//logData:wchar_t->string
return strlogData;
}
string CSmtpManagerApp::ws2s(const wstring &ws)
{
std::string curLocale = setlocale(LC_ALL, NULL);// curLocale = "C";
setlocale(LC_ALL, "chs");
const wchar_t* _Source = ws.c_str();
size_t _Dsize = 2 * ws.size() + 1;
char *_Dest = new char[_Dsize];
memset(_Dest,0,_Dsize);
wcstombs(_Dest,_Source,_Dsize);
std::string result = _Dest; delete []_Dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}
下载代码
BOOL CConfigInfo::UseCompanyLogSettingWhenNetworkIsOK(CString userLocalAppDirPath)
{
WebServiceSoapProxy service;
_ns1__GetCompanyLogSettingResponse *ns1__GetCompanyLogSettingResponse=new _ns1__GetCompanyLogSettingResponse;
if (!service.GetCompanyLogSetting(NULL,ns1__GetCompanyLogSettingResponse)== SOAP_OK)
{
return FALSE;
}else{
//char* test=new char[1000];
vector<unsigned short > s1=ns1__GetCompanyLogSettingResponse->GetCompanyLogSettingResult->char_;
char *str = new char[s1.size()+1];
copy(s1.begin(),s1.end(), str);
str[s1.size()]=0;
WriteIni(userLocalAppDirPath+COMPANYCONFIG_FILE_NAME,str);
UpdateIni(userLocalAppDirPath+CONFIG_FILE_NAME,userLocalAppDirPath+COMPANYCONFIG_FILE_NAME);
delete []str;
}
return TRUE;
}
VOID CConfigInfo::WriteIni(CString path,char* companyLogSetting)
{
//path.Replace((unsigned short)"\\ ",(unsigned short)"\\\\ ");
char *char_path=new char[path.GetLength()*2];
memset(char_path,0,path.GetLength()*2);
WideCharToMultiByte(CP_ACP,0,
path.GetBuffer(path.GetLength()),-1,
char_path,path.GetLength(),
NULL,NULL);
FILE *pFile=fopen(char_path,"wb");
int companyLogSetting_length=strlen(companyLogSetting);
fwrite(companyLogSetting,sizeof(char),companyLogSetting_length,pFile);
fflush(pFile);
fclose(pFile);
}
//代码中有遍历ini的代码
VOID CConfigInfo::UpdateIni(CString logPath_Src,CString logPath_Des)
{
char *char_logPath_Src=new char[logPath_Src.GetLength()*2];
memset(char_logPath_Src,0,logPath_Src.GetLength()*2);
WideCharToMultiByte(CP_ACP,0,
logPath_Src.GetBuffer(logPath_Src.GetLength()),-1,
char_logPath_Src,logPath_Src.GetLength(),
NULL,NULL);
char *char_logPath_Des=new char[logPath_Des.GetLength()*2];
memset(char_logPath_Des,0,logPath_Des.GetLength()*2);
WideCharToMultiByte(CP_ACP,0,
logPath_Des.GetBuffer(logPath_Des.GetLength()),-1,
char_logPath_Des,logPath_Des.GetLength(),
NULL,NULL);
char strAppNameTemp_company[1024];//所有AppName的返回
char *AppNameTemp_company[1024];
int sectionCount=0;//company inifile's section count
DWORD dwAppNameSize1 = GetPrivateProfileStringA(NULL,NULL,NULL,strAppNameTemp_company,1024,char_logPath_Des);
if(dwAppNameSize1>0)
{
CHAR *pAppName1 = new CHAR[dwAppNameSize1];
int nAppNameLen1=0; //?个AppName的?度
for(int i = 0;i<dwAppNameSize1;i++)
{
pAppName1[nAppNameLen1++]=strAppNameTemp_company[i];
if(strAppNameTemp_company[i]=='\0')
{
AppNameTemp_company[sectionCount]=new char[strlen(pAppName1)];
//AppNameTemp_gjl[k]=pAppName1;
strcpy(AppNameTemp_company[sectionCount],pAppName1);
sectionCount++;
memset(pAppName1,0,dwAppNameSize1);
nAppNameLen1=0;
}
}
}
char strAppNameTemp_local[1024];//所有AppName的返回?
char strKeyNameTemp_local[1024];//???个AppName的所有KeyName的返回?
char strReturnTemp_local[1024];//返回?
DWORD dwKeyNameSize;//???个AppName的所有KeyName的??度
//所有AppName的??度
//char_logPath_Src="c:\\test.ini";
DWORD dwAppNameSize = GetPrivateProfileStringA(NULL,NULL,NULL,strAppNameTemp_local,1024,char_logPath_Src);
if(dwAppNameSize>0)
{
CHAR *pAppName = new CHAR[dwAppNameSize];
int nAppNameLen=0; //?个AppName的?度
for(int i = 0;i<dwAppNameSize;i++)
{
pAppName[nAppNameLen++]=strAppNameTemp_local[i];
if(strAppNameTemp_local[i]=='\0')
{
dwKeyNameSize = GetPrivateProfileStringA(pAppName,NULL,NULL,strKeyNameTemp_local,1024,char_logPath_Src);
if(dwAppNameSize>0)
{
char *pKeyName = new char[dwKeyNameSize];
int nKeyNameLen=0; //?个KeyName的?度
for(int j = 0;j<dwKeyNameSize;j++)
{
pKeyName[nKeyNameLen++]=strKeyNameTemp_local[j];
if(strKeyNameTemp_local[j]=='\0')
{
GetPrivateProfileStringA(pAppName,pKeyName,NULL,strReturnTemp_local,1024,char_logPath_Src);
if (TRUE==IsContain(pAppName,AppNameTemp_company,sectionCount))
{
}else{
WritePrivateProfileStringA(pAppName,pKeyName,strReturnTemp_local,char_logPath_Des);
}
memset(pKeyName,0,dwKeyNameSize);
nKeyNameLen=0;
}
}
delete[]pKeyName;
}
memset(pAppName,0,dwAppNameSize);
nAppNameLen=0;
}
}
delete[]pAppName;
}
}
webservice代码
GetFiles.cs下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Text;
/// <summary>
/// GetFiles の概要の説明です
/// </summary>
public class GetFiles
{
public GetFiles()
{
//
// TODO: コンストラクター ロジックをここに追加します
//
}
static public void AcceptFile(string str,string name)
{
string path = "C:\\Down\\" + name;
FileStream fStream = new FileStream(path, FileMode.Create, FileAccess.Write);
byte[] result = System.Text.Encoding.Default.GetBytes(str);
fStream.Write(result, 0, str.Length);
fStream.Close();
}
static public char[] GetCompanyLogSetting()
{
byte[] byData = new byte[1000];
char[] charData = new char[1000];
string path = "C:\\Down\\company_config.ini";
FileStream fStream = new FileStream(path, FileMode.Open);
fStream.Seek(0, SeekOrigin.Begin);
fStream.Read(byData, 0, 1000);
Decoder d = Encoding.UTF8.GetDecoder();
d.GetChars(byData, 0, byData.Length, charData, 0);
Console.WriteLine(charData);
Console.ReadLine();
fStream.Close();
return charData;
}
}
WebService.cs下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// WebService の概要の説明です
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// この Web サービスを、スクリプトから ASP.NET AJAX を使用して呼び出せるようにするには、次の行のコメントを解除します。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//デザインされたコンポーネントを使用する場合、次の行をコメントを解除してください
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod(Description = "计算a+b=sum的功能")]
public int Add(int a, int b)
{
return a + b;
}
[WebMethod(Description = "显示问候语的功能")]
public string Show(string yourname)
{
return "popular" + "欢迎" + yourname;
}
[WebMethod(Description = "AddNumbers")]
public string AddNumbers(string NumberOne, string NumberTwo)
{
return "value:"+NumberOne+" "+NumberTwo;//NumberOne + NumberTwo + "hehe";
}
[WebMethod(Description = "upload")]
public void GetFileNew(string logData,string name)
{
GetFiles.AcceptFile(logData, name);
}
[WebMethod(Description = "GetCompanyLogSetting")]
public char[] GetCompanyLogSetting()
{
return GetFiles.GetCompanyLogSetting();
}
}
当然还需要配置webservice和webservice生成文件这些步骤,在我写的其他的文章有介绍。
c++ webservice(后续)(上传下载)
最新推荐文章于 2024-06-25 14:01:00 发布