免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1110 | 回复: 0
打印 上一主题 下一主题

soap开发之自定义Authorization的处理 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:44 |只看该作者 |倒序浏览
我遇到这个问题,因为是用qt开发,使用了第三方的gsoap进行设计,结果总是连不通服务器,但是去掉这个就正常工作了,所以可以断定是gsoap代码对于Authorization处理部分的代码的问题。于是仔细研究终于有所发现,原来真的没有做处理,只能自己加代码处理

例如:服务器端设计,
using System.Web.Services.Protocols; public class AuthHeader : SoapHeader { public string Username; public string Password; }

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /webservice/service1.asmx HTTP/1.1 Host: www.test.cn Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://www.test.cn/GetTest" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <AutherHeader xmlns="http://www.test.cn/"> <username>string</username> <userpwd>string</userpwd> </AutherHeader> </soap:Header> <soap:Body> <GetSingerAll xmlns="http://www.test.cn/" /> </soap:Body> </soap:Envelope> HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetSingerAllResponse xmlns="http://www.test.cn/"> <GetTestResult>string</GetTestResult> </GetTestResponse> </soap:Body> </soap:Envelope>

于是检查soapclient.cpp文件中的soap_call___ns2__GetTest函数,发现调用了soap_serialize___ns2__GetTest函数
再跟进去发现,没有处理header,于是在
soap_serialize___ns2__GetTest(soap, &soap_tmp___ns2__GetTest);之后添加 soap->header=soap_tmp___ns2__GetTest.ns1__GetTest->soap->header;

因为header是在request结构体中带的,调用时
struct soap soap; soap_init(&soap); struct SOAP_ENV__Header header; std::string user="test"; std::string passwd="123456"; header.ns1__AutherHeader_=new ns1__AutherHeader; header.ns1__AutherHeader_->username = &user; header.ns1__AutherHeader_->userpwd = &passwd; soap.header= &header;
_ns1__GetTest *quote = new _ns1__GetTest; _ns1__GetTestResponse *response = new _ns1__GetTestResponse; quote->soap=&soap;
soapObj.__ns2__GetTest(quote, response);

就ok了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP