69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include "wsdd.h"
int main(void){
struct soap *soap; //entirment variable
struct wsdd__ProbeType req; //client send probe
struct __wsdd__ProbeMatches resp; //server response prober
struct wsdd__ScopesType sScope; //Probel 里面的范围
struct SOAP_ENV__Header header;//soap header;
int result = 0;// return the value ;
int count = 0 ;//get the devices
GUID guid;
static char buf[64]= {0} ;
if(S_OK == CoCreateGuid(&guid)){
_snprintf(buf,sizeof(buf),"urn:uuid:%08X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X",
guid.Data1,guid.Data2,guid.Data3,
guid.Data4[0],guid.Data4[1],guid.Data4[2],guid.Data4[3],guid.Data4[4],guid.Data4[5],guid.Data4[6],guid.Data4[7]
);
}
soap = soap_new();//init soap
if(soap == NULL){
return -1 ;
}
soap_set_namespaces(soap,namespaces);
soap->recv_timeout = 5;
soap_default_SOAP_ENV__Header(soap,&header); //将header 设置为soap消息的头属性
//给头赋值
header.wsa__MessageID = buf;
header.wsa__To = "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
header.wsa__Action = "http://schemas.xmlsoap.org/ws/2005/04/discovery/Prob" ;
soap->header = &header;
/*设置设备所需查找设备的类型和范围,二者至少设定一个,否则可能受到非onvif设备,出现异常*/
soap_default_wsdd__ScopesType(soap,&sScope);
sScope.__item = "";
soap_default_wsdd__ProbeType(soap,&req);
req.Scopes = &sScope ;
req.Types="";
/*设置所需额设备的类型,tdn为命名空间前缀,为wsdd.nsmap文件中的前缀{tdn,http://www.onvif.org/ver10/network/wsdl"}的tdn,如果不是tdn是其他的如ns1,这里也要改为ns1 */
result = soap_send___wsdd__Probe(soap,"soap.udp://239.255.255.250:3702",NULL,&req);
if(result == -1){
printf("soap error:%s,%s,%s\n",soap->error,soap_faultcode(soap),soap_faultstring(soap));
//cout<<"soap error:"<<soap->error<<soap_faultcode(soap)<<"---"<<soap_faultstring(soap)<<endl;
}else{
do{
result = soap_recv___wsdd__ProbeMatches(soap,&resp);
if(result == -1){
//cout<<"共发现"<<cout<<"个设备"<<endl;
printf("共发现%d个设备\n",&result);
printf("soap error:%s,%s,%s\n",soap->error,soap_faultcode(soap),soap_faultstring(soap));
//cout<<"soap error:"<<soap->error<<soap_faultcode(soap)<<"--"<<soap_faultstring(soap)<<endl;
break;
}else {
count ++;
//cout<<"=================================================="<<endl;
printf("==================================================");
printf("UUID %s\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address);
//cout<<"UUID:"<<" "<<resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address<<endl;
printf("Type: %s\n",resp.wsdd__ProbeMatches->ProbeMatch->Types);
//cout<<"Type: "<<resp.wsdd__ProbeMatches->ProbeMatch->Types<<endl;
printf("Scopes: %s\n",resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item);
//cout<<"Scopes: "<<resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item<<endl;
printf("DeviceService Address: \n",resp.wsdd__ProbeMatches->ProbeMatch->XAddrs);
//cout<<"DeviceService Address: "<<resp.wsdd__ProbeMatches->ProbeMatch->XAddrs<<endl;
}
}while(1);
}
/***************清除变量**********************/
soap_destroy(soap); //remove deserialized class instances
soap_end(soap);
soap_done(soap);
getchar();
return result;
}
int result soap_recv___wsdd__ProbeMatches(soap,&resp);