onvif discovery server开发:
利用onvif device test Tool (ONVIF Device Test Tool 17.01 rev. 1140)点击搜索可以搜索到设备,但是点击probe 弹出XML文件有错误的提示,提示如下
unexpected error occurred:XML 文档(2,1734)中有错误
从服务器返回的xml文件如下:
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsdd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:tls="http://www.onvif.org/ver10/display/wsdl" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl"><SOAP-ENV:Header><wsa:MessageID>uuid:000b7508-1001-4adf-8702-000b75081001</wsa:MessageID><wsa:RelatesTo>uuid:243191be-96e1-4baf-9d9c-1715ae60803c</wsa:RelatesTo><wsa:To SOAP-ENV:mustUnderstand="true">urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To><wsa:Action SOAP-ENV:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</wsa:Action></SOAP-ENV:Header><SOAP-ENV:Body><wsdd:ProbeMatches><wsdd:ProbeMatch><wsa:EndpointReference><wsa:Address>urn:uuid:000b7508-1001-4adf-8702-000b75081001</wsa:Address><wsa:ReferenceProperties></wsa:ReferenceProperties><wsa:ReferenceParameters></wsa:ReferenceParameters><wsa:PortType>ttl</wsa:PortType></wsa:EndpointReference><wsdd:Types>dn:NetworkVideoTransmitter</wsdd:Types><wsdd:Scopes>onvif://www.onvif.org/type/NetworkVideoTransmitter onvif://www.onvif.org/location/city/guangzhou </wsdd:Scopes><wsdd:XAddrs>http://192.168.1.126/onvif/device_service</wsdd:XAddrs><wsdd:MetadataVersion>1</wsdd:MetadataVersion></wsdd:ProbeMatch></wsdd:ProbeMatches></SOAP-ENV:Body></SOAP-ENV:Envelope>
看来看去也没有看出什么问题出来,同样这个设备onvif device manager 也不能用,各位看官有什么好的看法
__wsdd__Probe函数实现如下:
SOAP_FMAC5 int SOAP_FMAC6 __wsdd__Probe(struct soap *psoap , struct wsdd__ProbeType *wsdd__Probe){printf("__wsdd__Probe\n");char _IPAddr[STR_SIZE_128];char _HwId[STR_SIZE_256];wsdd__ProbeMatchesType ProbeMatches;ProbeMatches.ProbeMatch = (struct wsdd__ProbeMatchType )soap_malloc(psoap,sizeof(struct wsdd__ProbeMatchType));ProbeMatches.ProbeMatch->XAddrs = (char )soap_malloc(psoap, sizeof(char) * STR_SIZE_128);ProbeMatches.ProbeMatch->Types = (char )soap_malloc(psoap, sizeof(char) * STR_SIZE_128);memset(ProbeMatches.ProbeMatch->Types,0,STR_SIZE_128);ProbeMatches.ProbeMatch->Types = (char )soap_malloc(psoap, sizeof(char) * STR_SIZE_128);ProbeMatches.ProbeMatch->Scopes = (struct wsdd__ScopesType)soap_malloc(psoap,sizeof(struct wsdd__ScopesType));ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceProperties = (struct wsa__ReferencePropertiesType)soap_malloc(psoap,sizeof(struct wsa__ReferencePropertiesType));ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceParameters = (struct wsa__ReferenceParametersType)soap_malloc(psoap,sizeof(struct wsa__ReferenceParametersType));ProbeMatches.ProbeMatch->wsa__EndpointReference.ServiceName = (struct wsa__ServiceNameType)soap_malloc(psoap,sizeof(struct wsa__ServiceNameType));ProbeMatches.ProbeMatch->wsa__EndpointReference.PortType = (char **)soap_malloc(psoap, sizeof(char *) * STR_SIZE_32);ProbeMatches.ProbeMatch->wsa__EndpointReference.__any = (char *)soap_malloc(psoap, sizeof(char) * STR_SIZE_32);ProbeMatches.ProbeMatch->wsa__EndpointReference.__anyAttribute = (char *)soap_malloc(psoap, sizeof(char) * STR_SIZE_32);ProbeMatches.ProbeMatch->wsa__EndpointReference.Address = (char )soap_malloc(psoap, sizeof(char) * STR_SIZE_128);strcpy(_HwId, endpoint_id);//macaddr[0]=0x01;macaddr[1]=0x01;macaddr[2]=0x01;macaddr[3]=0x01;macaddr[4]=0x01;macaddr[5]=0x01;//sprintf(_HwId,"urn:uuid:2419d68a-2dd2-21b2-a205-%02X%02X%02X%02X%02X%02X",macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);unsigned int localIp = 0;netGetIp("eth0", &localIp);ProbeMatches.__sizeProbeMatch = 1;ProbeMatches.ProbeMatch->Scopes->__item =(char )soap_malloc(psoap, STR_SIZE_4096);memset(ProbeMatches.ProbeMatch->Scopes->__item,0,sizeof(ProbeMatches.ProbeMatch->Scopes->__item));//Scopes MUST BEstrcat(ProbeMatches.ProbeMatch->Scopes->__item, "onvif://www.onvif.org/type/NetworkVideoTransmitter ");strcat(ProbeMatches.ProbeMatch->Scopes->__item, "onvif://www.onvif.org/location/city/guangzhou ");ProbeMatches.ProbeMatch->Scopes->MatchBy = NULL;sprintf(_IPAddr, "http://%s/onvif/device_service", inet_ntoa(((struct in_addr )&localIp)));strcpy(ProbeMatches.ProbeMatch->XAddrs, _IPAddr);strcpy(ProbeMatches.ProbeMatch->Types, wsdd__Probe->Types);printf("wsdd__Probe->Types=%s _IPAddr=%s\n",wsdd__Probe->Types, _IPAddr);ProbeMatches.ProbeMatch->MetadataVersion = 1;//ws-discovery规定 为可选项ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceProperties->__size = 0;ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceProperties->__any = NULL;ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceParameters->__size = 0;ProbeMatches.ProbeMatch->wsa__EndpointReference.ReferenceParameters->__any = NULL;ProbeMatches.ProbeMatch->wsa__EndpointReference.PortType[0] = (char )soap_malloc(psoap, sizeof(char) * STR_SIZE_32);//ws-discovery规定 为可选项strcpy(ProbeMatches.ProbeMatch->wsa__EndpointReference.PortType[0], "ttl_XXX");ProbeMatches.ProbeMatch->wsa__EndpointReference.ServiceName->__item = NULL;ProbeMatches.ProbeMatch->wsa__EndpointReference.ServiceName->PortName = NULL;ProbeMatches.ProbeMatch->wsa__EndpointReference.ServiceName->__anyAttribute = NULL;ProbeMatches.ProbeMatch->wsa__EndpointReference.__any[0] = (char )soap_malloc(psoap, sizeof(char) * STR_SIZE_32);strcpy(ProbeMatches.ProbeMatch->wsa__EndpointReference.__any[0], "Any");strcpy(ProbeMatches.ProbeMatch->wsa__EndpointReference.__anyAttribute, "Attribute");ProbeMatches.ProbeMatch->wsa__EndpointReference.__size = 0;strcpy(ProbeMatches.ProbeMatch->wsa__EndpointReference.Address, _HwId);/注释的部分为可选,注释掉onvif test也能发现ws-d///psoap->header->wsa__To = "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous";//psoap->header->wsa__Action = "http://schemas.xmlsoap.org/ws/2005/04/discovery/ProbeMatches";psoap->header->wsa__RelatesTo = (struct wsa__Relationship)soap_malloc(psoap, sizeof(struct wsa__Relationship));//it's herepsoap->header->wsa__RelatesTo->__item = psoap->header->wsa__MessageID;psoap->header->wsa__RelatesTo->RelationshipType = NULL;psoap->header->wsa__RelatesTo->__anyAttribute = NULL;psoap->header->wsa__MessageID =(char )soap_malloc(psoap, sizeof(char) * STR_SIZE_128);strcpy(psoap->header->wsa__MessageID,_HwId+4); / send over current socket as HTTP OK response: //测试过,第二参数必须http,action随意/ soap_send___wsdd__ProbeMatches(psoap, "http://", NULL, &ProbeMatches);return SOAP_OK;}