- 论坛徽章:
- 0
|
我遇到这个问题,因为是用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了
|
|