实现onvif 发现probe 功能返回error
最近在调试onvif功能。采用gsoap 2.8.15依据remotediscovery.wsdl、soapcpp2、wsdl2h、WS-typemap.dat生成代码。主函数如下。在虚拟机上运行client后,发现运行到soap_send___wsdd__Probe()后返回错误。请高手能帮忙。谢谢!
int main(int argc, char *argv[])
{
/* 变量声明 */
struct soap *soap; //soap环境变量
struct wsdd__ProbeType req; //用于发送消息描述
struct wsdd__ProbeType wsdd__Probe;
struct __wsdd__ProbeMatches resp;
//struct wsdd__ProbeMatchesType resp; //请求消息的回应
struct wsdd__ScopesType sScope; //描述查找哪类的Web服务
struct SOAP_ENV__Header header; //soap消息头描述
int count = 0; //获得的设信息备个数
int result = 0; //返回值
char uuid_string[64]; //存放uuid的(8-4-4-4-12)的格式
printf("%s : %d 000 : \n ",__FUNCTION__, __LINE__);
/************初始化*************/
memset(uuid_string, 0, 64);
strncpy(uuid_string,uuid_create_string(),36); //必须考虑到4个中间连字符
printf("uuid=%s \n ",uuid_string);
soap = soap_new(); //为soap申请变量空间,并初始化
if(soap==NULL)
return -1;
soap_set_namespaces(soap, namespaces); //设置soap的namespaces
printf("%s : %d \n ",__FUNCTION__, __LINE__);
soap->recv_timeout = 5; //超过5秒钟没有数据就退出
soap_default_SOAP_ENV__Header(soap, &header);//将header设置为soap消息 头属性
header.wsa__MessageID = uuid_string;
header.wsa__To = "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
header.wsa__Action = "http://schemas.xmllocal_soap.org/ws/2005/04/discovery/Probe";
soap->header = &header; //设置soap头消息的ID
printf("%s : %d \n ",__FUNCTION__, __LINE__);
/*设置所需寻找设备的类型和范围,二者至少设定一个,
否则可能收到非ONVIF设备,出现异常*/
//设置soap消息的请求服务属性
soap_default_wsdd__ScopesType(soap, &sScope);
sScope.__item = "";
//sScope.__item = "onvif://www.onvif.org";
soap_default_wsdd__ProbeType(soap, &req);
req.Scopes = &sScope;
/*设置所需设备的类型,ns1为命名空间前缀,为wsdd.nsmap文件中
{"tdn","http://www.onvif.org/ver10/network/wsdl"}的tdn,如果不是tdn,而是其它,
例如ns1这里也要随之改为ns1 */
req.Types="";
//req.Types = "tdn:NetworkVideoTransmitter";
printf("%s : %d \n ",__FUNCTION__, __LINE__);
//调用gSoap接口
//soap_wsdd_Probe
result = soap_send___wsdd__Probe(soap, "soap.udp://239.255.255.250:3702/", NULL, &req);
printf("%s: %d, send probe request success!\n",__FUNCTION__, __LINE__);
if(result==-1)
{
printf("soap error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
result = soap->error;
}
else
{
do
{
printf("%s: %d, begin receive probematch... \n",__FUNCTION__, __LINE__);
printf("count=%d \n",count);
//接收ProbeMatches,成功返回0,否则-1
result = soap_recv___wsdd__ProbeMatches(soap, &resp);
printf(" --soap_recv___wsdd__ProbeMatches() result=%d \n",result);
if (result==-1)
{
printf("Find %d devices!\n", count);
break;
}
else
{
//读取服务端回应的Probematch消息
printf("soap_recv___wsdd__Probe: __sizeProbeMatch=%d\r\n",resp.wsdd__ProbeMatches->__sizeProbeMatch);
printf("Target EP Address : %s\r\n", resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address);
printf("Target Type : %s\r\n", resp.wsdd__ProbeMatches->ProbeMatch->Types);
printf("Target Service Address : %s\r\n", resp.wsdd__ProbeMatches->ProbeMatch->XAddrs);
printf("Target Metadata Version : %d\r\n",resp.wsdd__ProbeMatches->ProbeMatch->MetadataVersion);
printf("Target Scopes Address : %s\r\n", resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item);
count++;
}
}while(1);
}
printf("%s : %d \n ",__FUNCTION__, __LINE__);
//清除soap
soap_end(soap); // clean up and remove deserialized data
soap_free(soap);//detach and free runtime context
soap_done(soap); // detach context (last use and no longer in scope)
return result;
}
以上运行后的结果为:
root@Daniel probe_test# ./deviceprobe
main : 45 000 :
uuid=afb17580-f6e3-11e5-baba-815e7fff3aba
main : 57
main : 65
main : 81
main: 86, send probe request success!
soap error: -1, (null), (null)
main : 122
段错误
还请高手帮忙解决,感谢~