gsoap 实现onvif 发现不了设备

fengyoujie 2014-06-05 02:26:33
诸位老师好!

最近再研究onvif和gsoap。
开发环境是win7+vs2010.
我参考的一个例子是:
http://blog.csdn.net/saloon_yuan/article/details/27524875
编译也能通过。我只是使用了我自己的main函数。
main.c的内容如下:

#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);

得到result的值为-1.。也就是说找不到设备。我用onvif Conformance Test tools 能找到局域网内的onvif设备。
请教诸位老师。多谢了。
...全文
312 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bch71 2016-11-18
  • 打赏
  • 举报
回复
楼主,你问题解决了吗??我也遇到类似的问题了???
iaamjerry 2014-07-16
  • 打赏
  • 举报
回复
header.wsa__Action = "http://schemas.xmlsoap.org/ws/2005/04/discovery/Prob" ; 最后面是Probe,不是Prob

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧