0

我是 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>

我想访问username在这个 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 标头的指针,这将是有帮助的。

4

1 回答 1

0

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

于 2013-01-15T11:28:06.667 回答