http://blog.csdn.net/kmblack1/article/details/6242999
使用VC++使用开发Web服务(ISAPI extension - mod_gsoap.dll)1
在本例中使用gsoap中的ISAPI extension 模块(mod_gsoap.dll).
本例中运行环境为WinXP SP3(32位) IIS5.1
本例中的开发工具为Microsoft Visual Studio 2008 SP1(32位)中文版.
1. 下载安装gsoap
下载gsoap_2.8.1.zip(http://gsoap2.sourceforge.net/)
解压gsoap_2.8.1.zip到硬盘(本例中使用D:/gsoap-2.8)
2. 设置VC开发环境.
可选步骤,在本例中不设置.
3. 重新编译ISAPI extension 模块(mod_gsoap.dll)
我下载的gsoap包中的默认ISAPI extension 模块运行错误,需要重新编译. 原始文件位置为(D:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/mod_gsoap.dll).
重命名D:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/mod_gsoap.dll为mod_gsoap.bak
打开解决方案D:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/ all4iis.dsw
解决方案中包含all4iis、calc、calcclnt、dime、dimeclnt、isapi六个项目. ISAPI extension 模块(mod_gsoap.dll)项目为isapi.编译项目isapi,出现一堆警告和错误,错误消息如下:
1>正在删除项目“isapi”(配置“Debug|Win32”)的中间文件和输出文件
1>正在编译...
1>HttpContext.cpp
1>d:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/gsoap/opsysadjust.h(12) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/string.h(215) : 参见“stricmp”的声明
1>d:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/gsoap/casecmpless.h(11) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/string.h(215) : 参见“stricmp”的声明
1>isapi.cpp
1>ISAPI_HttpContext.cpp
1>d:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/gsoap/opsysadjust.h(12) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/string.h(215) : 参见“stricmp”的声明
1>d:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/gsoap/casecmpless.h(11) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/string.h(215) : 参见“stricmp”的声明
1>./ISAPI_HttpContext.cpp(71) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/string.h(157) : 参见“strncpy”的声明
1>ISAPI_Server.cpp
1>d:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/gsoap/opsysadjust.h(12) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/string.h(215) : 参见“stricmp”的声明
1>d:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/gsoap/casecmpless.h(11) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/string.h(215) : 参见“stricmp”的声明
1>./ISAPI_Server.cpp(176) : warning C4018: “>”: 有符号/无符号不匹配
1>./ISAPI_Server.cpp(199) : warning C4996: 'std::basic_istream<_Elem,_Traits>::readsome': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/istream(724) : 参见“std::basic_istream<_Elem,_Traits>::readsome”的声明
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>ISAPI_SoapServerFactory.cpp
1>d:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/gsoap/casecmpless.h(11) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details.
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/string.h(215) : 参见“stricmp”的声明
1>./ISAPI_SoapServerFactory.cpp(231) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:/Program Files/Microsoft Visual Studio 9.0/VC/include/stdio.h(366) : 参见“sprintf”的声明
1>isapistream.cpp
1>正在生成代码...
1>正在编译资源...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>正在链接...
1> 正在创建库./Debug/mod_gsoap.lib 和对象./Debug/mod_gsoap.exp
1>ISAPI_Server.obj : error LNK2019: 无法解析的外部符号"public: virtual __thiscall soap::~soap(void)" (??1soap@@UAE@XZ),该符号在函数"unsigned long __cdecl serve(class mod_gsoap_interface const *,class ISAPI_HttpRequest &,class HttpResponse,class isapistream &)" (?serve@@YAKPBVmod_gsoap_interface@@AAVISAPI_HttpRequest@@VHttpResponse@@AAVisapistream@@@Z) 中被引用
1>ISAPI_Server.obj : error LNK2019: 无法解析的外部符号"public: __thiscall soap::soap(void)" (??0soap@@QAE@XZ),该符号在函数"unsigned long __cdecl serve(class mod_gsoap_interface const *,class ISAPI_HttpRequest &,class HttpResponse,class isapistream &)" (?serve@@YAKPBVmod_gsoap_interface@@AAVISAPI_HttpRequest@@VHttpResponse@@AAVisapistream@@@Z) 中被引用
1>../Debug/mod_gsoap.dll : fatal error LNK1120: 2 个无法解析的外部命令
1>生成日志保存在“file://D:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/gsoap/Debug/BuildLog.htm”
1>isapi - 3 个错误,个警告
========== 全部重新生成: 成功0 个,失败1 个,跳过0 个==========
打开错误列表信息修正警告和错误消息,首先修改错误消息
错误 12 error LNK2019: 无法解析的外部符号 "public: virtual __thiscall soap::~soap(void)" (??1soap@@UAE@XZ),该符号在函数 "unsigned long __cdecl serve(class mod_gsoap_interface const *,class ISAPI_HttpRequest &,class HttpResponse,class isapistream &)" (?serve@@YAKPBVmod_gsoap_interface@@AAVISAPI_HttpRequest@@VHttpResponse@@AAVisapistream@@@Z) 中被引用 ISAPI_Server.obj
错误 13 error LNK2019: 无法解析的外部符号 "public: __thiscall soap::soap(void)" (??0soap@@QAE@XZ),该符号在函数"unsigned long __cdecl serve(class mod_gsoap_interface const *,class ISAPI_HttpRequest &,class HttpResponse,class isapistream &)" (?serve@@YAKPBVmod_gsoap_interface@@AAVISAPI_HttpRequest@@VHttpResponse@@AAVisapistream@@@Z) 中被引用 ISAPI_Server.obj
错误 14 fatal error LNK1120: 2 个无法解析的外部命令 ../Debug/mod_gsoap.dll
打开项目isapi - Source Files - ISAPI_Server.cpp,找到#include "ISAPI_SoapServerFactory.h",换一行后添加以下代码
#ifdef __cplusplus
#ifndef WITH_LEAN
soap::soap()
{
}
#endif
#endif
#ifdef __cplusplus
#ifndef WITH_LEAN
soap::~soap()
{
}
#endif
#endif
重新编译项目isapi.编译过程中因为VC9.0安全函数的原因,还是有一堆警告,你可以修改警告的这些函数为安全函数,也可以忽略这些警告信息.编译成功后的dll为D:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/Debug/mod_gsoap.dll.
修改配置为Release-win32模式重新编译项目isapi. 编译成功后的dll为D:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/ mod_gsoap.dll
4. 配置IIS和gsoap.
在IIS站点根目录(默认为C:/Inetpub/wwwroot)创建一个文件夹(gsoap),然后把D:/gsoap-2.8/gsoap/mod_gsoap/gsoap_win/isapi/ mod_gsoap.dll复制到C:/Inetpub/wwwroot/gsoap中.
打开Internet信息服务,展开计算机名(本地计算机)-网站-默认网站,找到gsoap文件夹并选择属性,在目录中点击创建按钮,设置应用程序名为gsoap,设置执行权限为脚本和可执行文件,设置应用程序保护为高(独立),同时取消脚本资源访问、记录访问、读取、索引资源、写入、目录浏览之间的选择框,如下图:
5. 测试gsoap是否配置成功
打开浏览器,并输入http://localhost/gsoap/mod_gsoap.dll出现下列字样表示配置成功.
No gsoap server dll specified in request. Please add the name of your soap server dll, e.g. http://localhost/gsoap/mod_gsoap?calc
see WebWare gsoap ISAPI module documentation.
gsoap自带的samples客户端例子可能那里不太对,我也没仔细看. 例如calcclient运行出现以下错误:
SOAP 1.1 fault: SOAP-ENV:Client [no subcode]
"No XML root element"
Detail: [no detail]
在下一讲中我们创建一个简单的时间服务,进一步测试gsoap是否配置成功