尝试在Android上实现onvif客户端以与IP摄像机配合使用。 我想使用WS-Subscription实现事件订阅。 出于某些目的,我的请求提供了正确的响应,但是我的服务器未接收任何消息。在下面查看我的要求。
====请求====
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope
xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest</a:Action>
<a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>
<a:To s:mustUnderstand="1">http://192.168.0.239:8080/onvif/events</a:To>
</s:Header>
<s:Body
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Subscribe
xmlns="http://docs.oasis-open.org/wsn/b-2">
<ConsumerReference>
<a:Address>
http://192.168.0.247:9090/subscription-1
</a:Address>
</ConsumerReference>
<InitialTerminationTime>
PT60S
</InitialTerminationTime>
</Subscribe>
</s:Body>
</s:Envelope>
<tet:Timeout>PT1M</tet:Timeout>
<tet:MessageLimit>10</tet:MessageLimit>
</tet:PullMessages>
</e:Body>
</e:Envelope>
====响应====
<?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"
...>
<SOAP-ENV:Header>
<wsa5:ReplyTo SOAP-ENV:mustUnderstand="true">
<wsa5:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa5:Address>
</wsa5:ReplyTo>
<wsa5:To SOAP-ENV:mustUnderstand="true">http://192.168.0.239:8080/onvif/events</wsa5:To>
<wsa5:Action SOAP-ENV:mustUnderstand="true">http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeResponse</wsa5:Action>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<wsnt:SubscribeResponse>
<wsnt:SubscriptionReference>
<wsa5:Address>http://192.168.0.239:8080/onvif/Subscription?Idx=0</wsa5:Address>
</wsnt:SubscriptionReference>
<wsnt:CurrentTime>2018-06-20T10:16:22Z</wsnt:CurrentTime>
<wsnt:TerminationTime>2018-06-20T10:17:22Z</wsnt:TerminationTime>
</wsnt:SubscribeResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
====服务器====
class SimpleWebServer @Throws(IOException::class)
constructor() : NanoHTTPD(9090) {
override fun serve(session: IHTTPSession): Response {
val data = HashMap<String, String>()
val method = session.method
session.parseBody(data)
// get the POST body
val postBody = session.getQueryParameterString()
// or you can access the POST request's parameters
val postParameter = session.getParms()["parameter"]
Log.d("SimpleWebServer", "$method : $postBody")
return NanoHTTPD.newFixedLengthResponse("").also { response response.status = Response.Status.ACCEPTED } // Or postParameter.
}
}
答案 0 :(得分:0)
您的XML请求似乎不正确。 ONVIF core specs在第9.10节中提供了有关如何订阅事件的示例。它包含许多XML,因此不值得在此处复制。基本上,您要做的是以下任务列表:
GetEventPropertiesRequest
到受支持事件的列表(§9.10.1)CreatePullPointSubscription
创建PullPoint(§9.10.3)PullMessages
(第9.10.5节)获取事件Renew
和/或从中拉出Unsubscribe
。有关如何使用通知流界面的说明,请查看ONVIF Application Programming Guide的§7.6