首先将Gsoap plugin目录下的md5evp.h, md5evp.c, httpda.h,httpda.c,threads.h,threads.c文件加入到项目工程中
在实际编写代码的cpp文件中引入头文件 #include “httpda.h”
在编译的过程中会提示soap_memcpy 和 SOAP_SNPRINTF的相关错误,只需要在gsoap下找到对应的声明添加到 stdsoap2.h即可
在使用WS-UsernameToken方式进行权限验证时,如果验证不通过,那么将会返回400错误。 在使用Digest方式进行权限验证时,如果验证不通过,那么将返回401错误。
soap_call___ns_method(&soap, ...);
if (soap.status == 400)
{
soap_register_plugin(&soap, http_da);
soap.userid = "username";
soap.passwd = "password";
soap_call___ns_method(&soap, ...);
if (soap.status == 401)
{
struct http_da_info info; // to store userid and passwd
//soap.authrealm在验证失败从服务器返回
http_da_save(&soap, &info, soap.authrealm, "username", "password");
soap_call___ns_method(&soap, ...);
http_da_restore(&soap, &info);
http_da_release(&soap, &info);
}
}
大多设备支持ws-usernameToken方式,少些设备不支持,当权限验证存在冲突时则需要兼容处理。