How to send SOAP messages ?

I found some onvif cameras on our network. (Unfortunately none of them had PTZ.) But I did get them to respond to some SOAP packets I built in OptoScript. Here’s an example:

sHostname = "10.192.0.115"; // IP address of the camera
nPort = 888;                // port 80 is more typical
sURLPath = "/onvif/device_service";

//stPostHeader[0] = "POST /onvif/device_service HTTP/1.1"; // this part of the tcp packet is added by the call the HttpPostFromStringTable, not needed in header
stPostHeader[0] = "Content-Type: application/soap+xml; charset=utf-8; action=" + chr('"') + "http://www.onvif.org/ver10/device/wsdl/GetCapabilities" + chr('"');
stPostHeader[1] = "Content-Length: 297";  // this will get overwritten by a call to HttpPostCalcContentLength
stPostHeader[2] = "Accept-Encoding: gzip, deflate";
stPostHeader[3] = "Connection: Close";

// Now create the soap packet for the content of the HttpPost:
stPostContent[0] = "<?xml version=" + chr('"') + "1.0" + chr('"') + " encoding=" + chr('"') + "UTF-8" + chr('"') + "?>" +
 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=" + chr('"') + "http://www.w3.org/2003/05/soap-envelope" + chr('"') + " xmlns:tds=" + chr('"') + 
 "http://www.onvif.org/ver10/device/wsdl" + chr('"') + ">" +
 "<SOAP-ENV:Body>" +
 "<tds:GetDeviceInformation/>" +
 "</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope> ";
 
// Calculate the length of the content we're sending
nHTTPResult = HttpPostCalcContentLength(/*Post Content*/stPostContent, /*Post Header*/stPostHeader, /*Length Index*/1);

// Do the post -- if all goes ok this returns a 0 and some soap in the stResponseContent string table
nHTTPPostResult = HttpPostFromStringTable( stResponseContent, stResponseHeader, stPostContent, stPostHeader, nSecuritMode, sURLPath, nHTTPResult, nPort, sHostname );



Here’s what the preset command looked like: Same code as above, but the stPostContent[0] had that command we discussed earlier:



// PAN/TILT - go to a particular preset
stPostContent[0] = "<?xml version=" + chr('"') + "1.0" + chr('"') + " encoding=" + chr('"') + "utf-8" + chr('"') + "?>" + 
 "<soap:Envelope xmlns:soap=" + chr('"') + "http://www.w3.org/2003/05/soap-envelope" + chr('"') + " xmlns:tptz=" + chr('"') + "http://www.onvif.org/ver20/ptz/wsdl" + chr('"') + ">" + 
 "<soap:Body><tptz:GotoPreset>" + 
 "<tptz:ProfileToken>Profile1</tptz:ProfileToken>" +
 "<tptz:PresetToken>Preset1</tptz:PresetToken>" +
 "</tptz:GotoPreset>" +
 "</soap:Body>" +
 "</soap:Envelope>";


See pictures below for the response that came back on the GetDeviceInformation command, showing what Model of FOSCAM camera the R1 talked to


… and the SOAP error message for the preset that wasn’t going to work w/out a PTZ camera:


I hope that helps!