2024年5月30日发(作者:)

soap->header = header;

return soap;

}

//释放函数

void ONVIF_soap_delete(struct soap *soap)

{

soap_destroy(soap); // remove deserialized class instances (C++ only)

soap_end(soap); // Clean up deserialized data (except class instances) and temporary data

soap_free(soap); // Reset and deallocate the context created with soap_new or soap_copy

}

//鉴权

static int ONVIF_SetAuthInfo(struct soap *soap, const char *username, const char *password)

{

int result = 0;

if((NULL != username) || (NULL != password)){

soap_wsse_add_UsernameTokenDigest(soap, NULL, username, password);

}else{

printf("un etAuthn");

result = -1;

}

return result;

}

int main(int argc,char *argv[])

{

int i = 0;

int ret = 0;

char media_addr[] = "172.168.0.211/onvif/media_service"; //GetCapabilities得到的地址

char media_addr2[] = "172.168.0.211/onvif/media2_service"; //GetServices得到的地址

struct SOAP_ENV__Header header;

struct soap* soap = ONVIF_Initsoap(&header, NULL, NULL, 5);

struct _tr2__GetProfiles tr2__GetProfiles;

struct _tr2__GetProfilesResponse tr2__GetProfilesResponse;

tr2__GetProfiles.__sizeType = 1;

tr2__ = NULL;

tr2__ = NULL;

ONVIF_SetAuthInfo(soap,"admin","123456"); //鉴权

soap_call___tr2__GetProfiles(soap, media_addr2, NULL, &tr2__GetProfiles, &tr2__GetProfilesResponse);

if(soap->error){

ret = -1;

printf("soap error: %d, %s, %sn", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));

return ret;

}else{

for(i=0; i

{

printf( "Profiles Name:%s n",tr2__es[i].Name);

printf( "Profiles Taken:%sn",tr2__es[i].token);

}

}

ONVIF_soap_delete(soap);

return ret;

}

编译:gcc -o test get_ GetProfiles_test.c stdsoap2.c soapC.c md5.c dom.c mecevp.c smdevp.c threads.c wsaapi.c wsseapi.c soapClient.c -I

import/ -DWITH_OPENSSL -lssl -lcrypto -ldl -pthread

结果: