Einzelnen Beitrag anzeigen

Benutzerbild von TERWI
TERWI

Registriert seit: 29. Mär 2008
Ort: D-49626
379 Beiträge
 
Delphi 11 Alexandria
 
#15

AW: WebServices - Discovery: Hello, Probe, Bye ......

  Alt 8. Feb 2016, 18:27
Ich möchte euch ja nicht vorenthalten, wie das mit eigentlich minimalistischem Code funktioniert.

Ich habe dafür nur einen UDP-Server benutzt, der beides macht:
Daten versenden und gleichzeitig empangen.
Die eigentliche procedure zur Anfrage als Broadcast via UDP:
Code:
procedure TForm1.Button2Click(Sender: TObject);
var
  SndBytes : TIdBytes;
begin
  with udpServer do
  begin
    Active := false;            // proforma FALSE / stoppen
    Bindings.DefaultPort := strtoint(EditRcvPort.text);
    BroadcastEnabled := true; //
    Active := True;             // ... und wieder starten
    ONVIF.GenSendBytes_PROBE(SndBytes);
    udpServer.SendBuffer(EditHost.Text, strtoint(EditPort.text), SndBytes);
    Memo1.Lines.Add('Data send to: ' + EditHost.Text + ':' + EditPort.text);
    Memo1.Lines.Add('Server started on port: ' + EditRcvPort.text);
  end;
end;
Die procedure, woher obige den SOAP/XML-String her bekommt:
Code:
procedure TONVIF.GenSendBytes_PROBE(var SndBytes : TIdBytes);
var
  s : string;
begin
  s := '<?xml version="1.0" encoding="UTF-8"?>' +
    '<e:Envelope xmlns:e="http://www.w3.org/2003/05/soap-envelope"' +
    'xmlns:w="http://schemas.xmlsoap.org/ws/2004/08/addressing"' +
    'xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery"' +
    'xmlns:dn="http://www.onvif.org/ver10/network/wsdl">'+
    '<e:Header>' +
    '<w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID>' +
    '<w:To e:mustUnderstand="true">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To>' +
    '<w:Action a:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action>' +
    '</e:Header>' +
    '<e:Body>' +
    '<d:Probe>' +
    '<d:Types>dn:NetworkVideoTransmitter</d:Types>' +
    '</d:Probe>' +
    '</e:Body>' +
    '</e:Envelope>';
  SetLength(SndBytes, Length(s) + 1);
  fillchar(SndBytes[0], length(s) + 1, 0);
  move(s[1], SndBytes[0], Length(s));
end;
.... und die procedure im Receive-Event des UDP-Servers:
Code:
procedure TForm1.UDPServerUDPRead(AThread: TIdUDPListenerThread;
          const AData: TIdBytes; ABinding: TIdSocketHandle);
begin
  Memo1.Lines.Add(' Server read num of bytes: ' + inttostr(length(AData)));
  Memo1.Lines.Add(' - from > IP: ' + ABinding.PeerIP + ' | Port: ' + inttostr(ABinding.PeerPort));
  Memo1.Lines.Add(BytesToString(AData));
end;
Dabei kommt dann z.B. so etwas als "Seifen-Oper" von der Kamera zurück:
(Händisch formatiert ohne Einrückungen für die Optik)
Code:
<?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:wsa5="http://www.w3.org/2005/08/addressing"
 xmlns:xop="http://www.w3.org/2004/08/xop/include"
 xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
 xmlns:tt="http://www.onvif.org/ver10/schema"
 xmlns:ns1="http://www.w3.org/2005/05/xmlmime"
 xmlns:wstop="http://docs.oasis-open.org/wsn/t-1"
 xmlns:ns7="http://docs.oasis-open.org/wsrf/r-2"
 xmlns:ns2="http://docs.oasis-open.org/wsrf/bf-2"
 xmlns:dndl="http://www.onvif.org/ver10/network/wsdl/DiscoveryLookupBinding"
 xmlns:dnrd="http://www.onvif.org/ver10/network/wsdl/RemoteDiscoveryBinding"
 xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery"
 xmlns:dn="http://www.onvif.org/ver10/network/wsdl"
 xmlns:ns10="http://www.onvif.org/ver10/replay/wsdl"
 xmlns:ns11="http://www.onvif.org/ver10/search/wsdl"
 xmlns:ns13="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding"
 xmlns:ns14="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding"
 xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl"
 xmlns:ns15="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding"
 xmlns:ns16="http://www.onvif.org/ver10/events/wsdl/EventBinding"
 xmlns:tev="http://www.onvif.org/ver10/events/wsdl"
 xmlns:ns17="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding"
 xmlns:ns18="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding"
 xmlns:ns19="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding"
 xmlns:ns20="http://www.onvif.org/ver10/events/wsdl/PullPointBinding"
 xmlns:ns21="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding"
 xmlns:ns22="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding"
 xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
 xmlns:ns3="http://www.onvif.org/ver10/analyticsdevice/wsdl"
 xmlns:ns4="http://www.onvif.org/ver10/deviceIO/wsdl"
 xmlns:ns5="http://www.onvif.org/ver10/display/wsdl"
 xmlns:ns8="http://www.onvif.org/ver10/receiver/wsdl"
 xmlns:ns9="http://www.onvif.org/ver10/recording/wsdl"
 xmlns:tds="http://www.onvif.org/ver10/device/wsdl"
 xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"
 xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl"
 xmlns:trt="http://www.onvif.org/ver10/media/wsdl"
 xmlns:ter="http://www.onvif.org/ver10/error"
 xmlns:tns1="http://www.onvif.org/ver10/topics"
 xmlns:tnsn="http://www.eventextension.com/2011/event/topics">
<SOAP-ENV:Header>
<wsa:MessageID>urn:uuid:327b23c6-5566-7788-99aa-0012152b823d</wsa:MessageID>
<wsa:RelatesTo>uuid:84ede3de-7dec-11d0-c360-f01234567890</wsa:RelatesTo>
<wsa:To SOAP-ENV:mustUnderstand="true">
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:To>
<wsa:Action SOAP-ENV:mustUnderstand="true">
http://schemas.xmlsoap.org/ws/2005/04/discovery/ProbeMatches
</wsa:Action>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<d:ProbeMatches><d:ProbeMatch><wsa:EndpointReference>
<wsa:Address>urn:uuid:327b23c6-5566-7788-99aa-0012152b823d</wsa:Address>
</wsa:EndpointReference>
<d:Types>dn:NetworkVideoTransmitter</d:Types>
<d:Scopes>
onvif://www.onvif.org/type/video_encoder
 onvif://www.onvif.org/type/audio_encoder
 onvif://www.onvif.org/hardware/IPC-model
 onvif://www.onvif.org/location/country/china
 onvif://www.onvif.org/name/NVT
</d:Scopes>
<d:XAddrs>http://192.168.178.39:8899/onvif/device_service</d:XAddrs>
<d:MetadataVersion>1</d:MetadataVersion>
</d:ProbeMatch></d:ProbeMatches>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
... 627 Byte allerfeinstes WebService-WSDL-SOAP-XML-Kauderwelsch !
... wovon mich eigentlich nur interessiert:

<wsa:MessageID>urn:uuid:327b23c6-5566-7788-99aa-0012152b823d</wsa:MessageID>
(gleich mit wsa:Address - immer !?)
<wsa:RelatesTo>uuid:84ede3de-7dec-11d0-c360-f01234567890</wsa:RelatesTo>
(zum Vergleich - die uuid hab ich geschickt)
<d:Scopes> .... </d:Scopes>
(die hier 5 darin entahltenen Typen, durch Leerzeichen getrennt)
... und wichtig
<d:XAddrs>http://192.168.178.39:8899/onvif/device_service</d:XAddrs>
hier eigenlich nur der Port für weitere Ansagen per HTTP. Die IP kenne ich ha schon aus dem eigentlichen Response vom Binding des UDP-Servers.


Als NOOB in diesem Bereich fällt mir als erstes die gute alte funktion POS ein, hier die elementar 3 bis 8 wichtigen Werte mit nem 5-Zeiler rauszubröseln.

Oder hat hemand da vielleicht eine (simplere) Idee ?
Lasst hören !

Geändert von TERWI ( 8. Feb 2016 um 18:30 Uhr)
  Mit Zitat antworten Zitat