关于正常怎么使用gSOAP的话,下面那篇博客已经讲得非常详细,我就不再赘述了
https://www.cnblogs.com/dengpeng1004/p/6165751.html
问题1:
WCF server with basicHttpBinding use soap1.1, while gSoap generates client that uses soap1.2.
如果你使用的gSOAP是1.2版本,而WebServer服务器是1.0版本,WCF server 和 gSoap产生的 client端之间通讯的soap message format不匹配。当客户端发起请求时,server端无法识别请求。但是你如果为了版本去另下一个gSOAP,时间成本有点多,其实gSOAP有向下兼容的功能。那现在我们看看如何来生成1.0版本的服务端。
在生成好的WebServer.h中修改101行到103行。
// This service uses SOAP 1.2 namespaces:
//gsoap SOAP-ENV schema namespace: http://www.w3.org/2003/05/soap-envelope
//gsoap SOAP-ENC schema namespace: http://www.w3.org/2003/05/soap-encoding
改为
// This service uses SOAP 1.1 namespaces:
//gsoap SOAP-ENV schema namespace: http://schemas.xmlsoap.org/soap/envelope/
//gsoap SOAP-ENC schema namespace: http://schemas.xmlsoap.org/soap/encoding/
同时在解析WebServer.h时,将命令
在命令行输入soapcpp2 -C WebService.h -I F:\WebService\gsoap-2.7\gsoap\import
改为
在命令行输入soapcpp2 -C WebService.h -I F:\WebService\gsoap-2.7\gsoap\import -1
-1代表1.1版本,这样版本冲突的问题就解决了。
WebServer 是wstring 的指针类型,wchar_t *,我怎么接收呢
最好使用CString类型来接收字符串内容
wchar_t* 直接使用CString
wstring的话
CStringW a;
std::wstring b;
a=b.c_str();
传回来的是结构体怎么办
定义结构体遍历返回值
#define DllWebServerLoginAPI _declspec(dllexport)
#include <stdio.h>
#include <string>
#include "atlconv.h"
#include "BasicHttpBinding_USCOREIUserService.nsmap"
#include "soapBasicHttpBinding_USCOREIUserServiceProxy.h"
#include "atlstr.h"
using namespace std;
struct CKECKMENU
{
CStringW DisplayOrder;
CString FatherId;
CString FileDir;
CString Icon;
CString Id;
CString InnetAppIp;
CString Link;
CString ModuleId;
CString Name;
CString OilnetAppIp;
CString OpenMode;
CString OutnetAppIp;
CStringW SelectWellType;
CString WellSelect;
}; DllWebServerLoginAPI vector<class CKECKMENU > GetUsefulMenus( wchar_t* sid)
{
BasicHttpBinding_USCOREIUserService proxy(SOAP_C_UTFSTRING); _WS1__GetUsefulMenus getMenu;
getMenu.sid=sid; _WS1__GetUsefulMenusResponse getMenuMenusResponse;
if (proxy.__WS1__GetUsefulMenus(&getMenu, &getMenuMenusResponse) == SOAP_OK)
{
CKECKMENU* view =new CKECKMENU;
std::vector<class CKECKMENU >Menu; for(int i=;i<getMenuMenusResponse.GetUsefulMenusResult->Menu.size();i++)
{
wchar_t str[]; wcscpy(str, getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->DisplayOrder->c_str()); //_wcslwr_s(str, wcslen(getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->DisplayOrder->c_str()) + 1); view->DisplayOrder=str;
view->FatherId=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->FatherId;
view->FileDir=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->FileDir;
view->Icon=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->Icon;
view->Id=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->Id;
view->InnetAppIp=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->InnetAppIp;
view->Link=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->Link;
view->ModuleId=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->ModuleId;
view->Name=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->Name;
view->OilnetAppIp=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->OilnetAppIp;
view->OpenMode=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->OpenMode;
view->OutnetAppIp=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->OutnetAppIp;
view->SelectWellType=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->SelectWellType->c_str();
view->WellSelect=getMenuMenusResponse.GetUsefulMenusResult->Menu[i]->WellSelect;
Menu.push_back(*view); }
return Menu; } }
传回来的文字乱码怎么办?
统一使用CString来接收字符