我遇到这个问题,因为是用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:
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http:///GetTest"
string
string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
string
于是检查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了
阅读(2461) | 评论(0) | 转发(0) |