gpt4 book ai didi

c++ - 如何在 C 中访问 SOAP header

转载 作者:行者123 更新时间:2023-11-30 17:56:40 24 4
gpt4 key购买 nike

我是 SOAP 新手,正在尝试实现用户身份验证,请提供一些帮助,

这是从客户端发送的 XML 请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tt="http://www.onvif.org/ver10/schema"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<soapenv:Header>
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>

<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wssusername-token-profile-
1.0#PasswordDigest">tuOSpGlFlIXsozq4HFNeeGeFLEI=</wsse:Password>
<wsse:Nonce>LKqI6G/AikKCQrN0zqZFlg==</wsse:Nonce>
<wsu:Created>2010-09-16T07:50:45Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<tds:SetHostname>
<tds:Name>camera1</tds:Name>
</tds:SetHostname>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我想访问此 XML 请求中发送的用户名

在 Soap 生成的 SoapServer.c 中,它有一个名为

的函数
     `SOAP_FMAC5 int SOAP_FMAC6 soap_serve___tds__SetHostname(struct soap *soap)

下面的函数是将 xml 解析为 SOAP 结构的地方,

`

SOAP_FMAC5 int SOAP_FMAC6 soap_serve___tds__SetHostname(struct soap *soap) {

struct __tds__SetHostname soap_tmp___tds__SetHostname;
struct _tds__SetHostnameResponse tds__SetHostnameResponse;
soap_default__tds__SetHostnameResponse(soap, &tds__SetHostnameResponse);
soap_default___tds__SetHostname(soap, &soap_tmp___tds__SetHostname);
soap->encodingStyle = NULL;
if (!soap_get___tds__SetHostname(soap, &soap_tmp___tds__SetHostname, "-tds:SetHostname", NULL))
return soap->error;
if (soap_body_end_in(soap)
|| soap_envelope_end_in(soap)
|| soap_end_recv(soap))
return soap->error;
soap->error = __tds__SetHostname(soap, soap_tmp___tds__SetHostname.tds__SetHostname, &tds__SetHostnameResponse);
if (soap->error)
return soap->error;
soap_serializeheader(soap);
soap_serialize__tds__SetHostnameResponse(soap, &tds__SetHostnameResponse);
if (soap_begin_count(soap))
return soap->error;
if (soap->mode & SOAP_IO_LENGTH)
{ if (soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put__tds__SetHostnameResponse(soap, &tds__SetHostnameResponse, "tds:SetHostnameResponse", NULL)
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap))
return soap->error;
};
if (soap_end_count(soap)
|| soap_response(soap, SOAP_OK)
|| soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put__tds__SetHostnameResponse(soap, &tds__SetHostnameResponse, "tds:SetHostnameResponse", NULL)
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap)
|| soap_end_send(soap))
return soap->error;
return soap_closesock(soap);
}

`因此尝试在此方法中访问/打印用户名(从现在的基本访问开始)

fprintf(stderr,"%s\n",soap->header->wsse__Security->UsernameToken->Username);

但是这每次都会打印一些垃圾值,通过指向结构来访问用户名也是完全正确的,如果有人给出一些关于如何访问 SOAP header 的指示,那将会很有帮助。

最佳答案

这取决于您尝试在哪里打印此用户名,因为它会在最后删除结构。如果您只想将用户名从客户端发送到服务器,则将其作为参数发送给soap_send/soap_call(根据同步/异步函数)函数。检查 SOAP 客户端服务器通信以获取更多详细信息。一方面您只是发送信息,另一方面接收肥皂将在内部处理的其他事情。

关于c++ - 如何在 C 中访问 SOAP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13344941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com