im trying to get live stream from onvif devices my program searchs and finds cameras IP and onvif Port successfully,but in the next step to get device information i face this error :
there was no endpoint listening at http://192.168.1.89/onvif/device_service that could accept the message.this often cause by an incorrect address or SOAP action.
i dont know what is wrong with my code even i want to get the time and date from the devices there is the same error! my code is :
private Device deviceChannel = null;
private System.ServiceModel.Channels.Binding binding = null;
private string serverNetworkAddress;
private string serviceAddress;
private string serverUsername = "";
private string serverPassword = "";
InitializeComponent();
serverUsername = OnvifUserTextBox.Text;
serverPassword = OnvifPwdTextBox.Text;
serverNetworkAddress = serverAddrTextBox.Text;
serviceAddress = string.Format("http://{0}/onvif/device_service", serverNetworkAddress);
//Create Binding
binding = CreateBinding();
private static System.ServiceModel.Channels.Binding CreateBinding()
{
HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
TransportSecurityBindingElement transportSecurity = new TransportSecurityBindingElement();
transportSecurity.EndpointSupportingTokenParameters.SignedEncrypted.Add(
new UsernameTokenParameters());
transportSecurity.AllowInsecureTransport = true;
transportSecurity.IncludeTimestamp = false;
TextMessageEncodingBindingElement me =
new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8);
return new CustomBinding(transportSecurity, me, httpTransport);
}
private static TChannel GetChannel<TChannel> (System.ServiceModel.Channels.Binding binding,
string serviceAddressText,
string serverUsername,
string serverPassword)
{
EndpointAddress serviceAddress = new EndpointAddress(serviceAddressText);
ChannelFactory<TChannel> channelFactory =
new ChannelFactory<TChannel>(binding, serviceAddress);
// configure the username credentials on the channel factory
UsernameClientCredentials credentials =
new UsernameClientCredentials(new UsernameInfo(serverUsername, serverPassword));
// replace ClientCredentials with UsernameClientCredentials
channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
channelFactory.Endpoint.Behaviors.Add(credentials);
return channelFactory.CreateChannel();
}
private void button2_Click(object sender, EventArgs e)
{
//getting the device information
listBox.Items.Clear();
serverUsername = OnvifUserTextBox.Text;
serverPassword = OnvifPwdTextBox.Text;
serverNetworkAddress = serverAddrTextBox.Text;
serviceAddress = string.Format("http://{0}/onvif/device_service", serverNetworkAddress);
// string model, firmwareVersion, serialNumber, hardwareId;
try
{
// Create a client with given client endpoint configuration
deviceChannel =
GetChannel<Device>(binding, serviceAddress, serverUsername, serverPassword);
// deviceChannel.GetDeviceInformation= ( out model, out FirmwareVersion, out SerialNumber, out HardwareId);
//get date and time
var timemamo = deviceChannel.GetSystemDateAndTime();
listBox.Items.Add(timemamo);
var info = deviceChannel.GetDeviceInformation(new GetDeviceInformationRequest());
//MessageBox.Show(string.Format("Model: {0}", info.Model));
string strManuf = string.Format("Manufacturer: {0}", info.Manufacturer);
listBox.Items.Add(strManuf);
string strModel = string.Format("Model: {0}", info.Model);
listBox.Items.Add(strModel);
string strFw = string.Format("Firmware Version: {0}", info.FirmwareVersion);
listBox.Items.Add(strFw);
string strSerialNo = string.Format("Serial Number: {0}", info.SerialNumber);
listBox.Items.Add(strSerialNo);
string strHwId = string.Format("Hardware Id: {0}", info.HardwareId);
listBox.Items.Add(strHwId);
}
catch (Exception exception)
{
string str = string.Format("GetDeviceInformation():mamo " + exception.Message);
listBox.Items.Add(str);
}
}