Onvif - GetStreamUri说" XML格式错误发生"

时间:2016-07-14 12:24:58

标签: xml onvif

如何构建Onvif GetStreamUrl消息?我已经尝试了数以百万计的可能性,其中之一是:

   <?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Header>
    <Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <UsernameToken><Username>onvif</Username>
      <Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">tFvFfoo7ZZhmKv61tTBJ4agS/lM=</Password>
      <Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NTcxNjg1NTQwNzg2Mzcx</Nonce>
      <Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2016-07-14T14:02:27Z</Created>
      </UsernameToken>
    </Security>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <GetStreamUri xmlns="http://www.onvif.org/ver10/media/wsdl">
      <StreamSetup>
    <StreamType>RTP-Unicast</StreamType>
    <Transport>
      <TransportProtocol>UDP</TransportProtocol>
    </Transport>
      </StreamSetup>
      <ReferenceToken>profile_1_h264</ReferenceToken>
    </GetStreamUri>
  </s:Body>
</s:Envelope>

官方规范如下:http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl#op.GetStreamUri

有没有人可以帮助我?

2 个答案:

答案 0 :(得分:0)

如果您想自己制作信封,可以使用以下测试模板并制作包含SOAP信封的http请求。

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
    <s:Header>
        <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
            <wsse:UsernameToken wsu:Id="SecurityToken-906d1a56-c091-4d33-8afa-04445dd123ff" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                <wsse:Username>admin</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">THHcq7prwwf/42S+A5tuorg/RMY=</wsse:Password>
                <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">f11vJWByh7IJBvZRi46Qeg==</wsse:Nonce>
                <wsu:Created>2016-10-19T05:42:47Z</wsu:Created>
            </wsse:UsernameToken>
        </Security>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <GetStreamUri xmlns="http://www.onvif.org/ver10/media/wsdl">
            <StreamSetup>
                <Stream xmlns="http://www.onvif.org/ver10/schema">RTP-Unicast</Stream>
                <Transport xmlns="http://www.onvif.org/ver10/schema">
                    <Protocol>UDP</Protocol>
                </Transport>
            </StreamSetup>
            <ProfileToken>2_def_profile1</ProfileToken>
        </GetStreamUri>
    </s:Body>
</s:Envelope>

但是使用onvif媒体服务,您可以获取配置文件,选择其中一个并使用您首选的StreamSetup和所选配置文件的令牌调用GetStreamUri方法。

答案 1 :(得分:0)

您在请求正文中使用TransportProtocol而不是Protocol来获取版本10的ONVIF规范(https://www.onvif.org/ver10/media/wsdl/media.wsdl)。

接下来,我在GetStreamUri调用中遇到了有关“发生XML格式错误的相同问题”。将xmlns方案添加到StreamTransport可以解决此问题。

<Stream xmlns="http://www.onvif.org/ver10/schema">RTP-Unicast</Stream>
<Transport xmlns="http://www.onvif.org/ver10/schema">
    <Protocol>UDP</Protocol>
</Transport>