VC2010 调用 Webservice

时间:2022-04-07 12:29:03
开发环境:VC2010,gsoap_2.8.23
使用soapcpp2的时候要加参数-i
3个文件去掉预编译头
在调用的地方包含这两个头文件:

#include "MobileServiceImplServiceSoapBinding.nsmap"

#include "soapMobileServiceImplServiceSoapBindingProxy.h"

8月28日在做登录模块,调用服务器webservice的时候汉字总是返回乱码,8月29日终于调好了。

在调用的构造函数中:

setlocale(LC_ALL , "chs");  //设置语言环境 包含

以及代理类增加了一个参数:SOAP_C_MBSTRING

代码如下:

                 CString formatStr ;

                 formatStr.Format (_T( "%s%s" ),

                                 this->m_strUserName .Trim(), this->m_strPassword .Trim());

                 TRACE(formatStr + _T( "\r\n"));

                 MobileServiceImplServiceSoapBindingProxy proxy( SOAP_C_MBSTRING); //SOAP_C_UTFSTRING、SOAP_C_MBSTRING

                 ns1__srvObjectOut srvObjectOut ;

                 srvObjectOut.ns1__queryXmlDoc = formatStr. GetBuffer();

                 srvObjectOut.ns1__jkxlh = "01A6D48EA5316A3DB5B5BB9EE0D89590";

                 srvObjectOut.ns1__jkid = "AW001";

                 const char endpoint[] = "http://localhost:8080/VIMSystem/Services/MobileService" ;

                 ns1__srvObjectOutResponse srvObjectOutResponse ;

                 int rtn = proxy. srvObjectOut(endpoint , NULL, & srvObjectOut, srvObjectOutResponse );

                 CString rtnStr ;

                 rtnStr.Format (_T( "返回值:%d\r\n返回内容:%s\r\n" ), rtn, srvObjectOutResponse.return_ );

                 TRACE(rtnStr );

VC2010 调用 Webservice 本文用菊子曰发布