1. 程式人生 > >C++通過webservice 訪問C#資料庫

C++通過webservice 訪問C#資料庫

知識總結

將桌面資料儲存於資料庫中

1、先打通 webserivce 到資料庫通道,這一步比較簡單,

通過呼叫 bll- dal - asmx 三層依次呼叫訪問。

2、c++桌面通過呼叫介面

定義介面做了一段串拼接抄作

 int CSeatArrangeMainDlg::WriteSeatSettingInfoIntoDB(int RoomId, string TeacherIP, string TeacherMac, int SeatRowCount, int SeatColCount,
int SeatArrangeDirect, string StuIPStart, string StuIPEnd, string RoomComputerNum, string HostMacAddr, int ElectricType,
string RoomVersion, string CentralIP, int CentralPort, string TerminalIP, int TerminalPort, string RecordServerIP)
 {
CString strUrl = L"http://localhost:2782/WebService/Mgr_Classroom.asmx/";    strUrl=GetUrl();
if (strUrl.IsEmpty())
{
return -2;
}
CString strWebMethodName = _T("WS_G_CRMgr_WriteSeatSettingInfoIntoDB");
strUrl += strWebMethodName;
strUrl += _T("?");
string strParameters = "";
strParameters += "RoomId=";
strParameters += to_string(RoomId);
strParameters += "&TeacherIP=";
strParameters += TeacherIP;
strParameters += "&TeacherMac=";
strParameters += TeacherMac;
strParameters += "&SeatRowCount=";
strParameters += to_string(SeatRowCount);
strParameters += "&SeatColCount=";
strParameters += to_string(SeatColCount);
strParameters += "&SeatArrangeDirect=";
strParameters += to_string(SeatArrangeDirect);
strParameters += "&StuIPStart=";
strParameters += StuIPStart;
strParameters += "&StuIPEnd=";
strParameters += StuIPEnd;
strParameters += "&RoomComputerNum=";
strParameters += RoomComputerNum;
strParameters += "&HostMacAddr=";
strParameters += HostMacAddr;
strParameters += "&ElectricType=";
strParameters += to_string(ElectricType);
strParameters += "&RoomVersion=";
strParameters += RoomVersion;
strParameters += "&CentralIP=";
strParameters += CentralIP;
strParameters += "&CentralPort=";
strParameters += to_string(CentralPort);
strParameters += "&TerminalIP=";
strParameters += TerminalIP;
strParameters += "&TerminalPort=";
strParameters += to_string(TerminalPort);
strParameters += "&RecordServerIP=";
strParameters += RecordServerIP;
strUrl += LGTools::StringToCString(strParameters);
LGTools::ConvertGBKToUtf8(strUrl);


string strGetInfo;
CWebCommand pWebCommond;
int iRet = pWebCommond.HttpGet(strUrl, NULL, strGetInfo);
int iCRID = LGTools::ParseIntReturnValueFromHttpGet(strGetInfo);


return iCRID;
 }

2總結

a、剛開始時候自己未除錯成功,主要問題出在webservice 不熟悉,拼接字元連個HTTP都沒有寫上

b、中間一定不要有任何空格符號不然肯定會錯的

總結 感悟