public byte[] BuildHello( string[] scopes, string types, XmlQualifiedName[] typesNamespaces, string[] xAddrs, uint metadataVersion) { WSD.HelloType hello = new WSD.HelloType(); // Scopes hello.Scopes = BuildScopes(scopes, null); // Types hello.Types = types; // EndpointReference hello.EndpointReference = BuildEndpointReference(); //hello.EndpointReference = new WSD.EndpointReferenceType(); // XAddrs hello.XAddrs = BuildXAddrs(xAddrs); // MetadataVersion hello.MetadataVersion = metadataVersion; byte[] msg = SoapBuilder.BuildMessage( hello, Encoding.UTF8, new DiscoveryHeaderBuilder(), new XmlSerializerNamespaces(typesNamespaces)); return(msg); }
/// <summary> /// Validates incoming Hello message /// </summary> /// <param name="message">Hello message</param> /// <param name="reason">reason why message is invalid, null if message is valid</param> /// <returns>true, if message is valid</returns> protected bool ValidateHelloMessage(SoapMessage <WSD.HelloType> message, string[] scopes, out string reason) { bool res = true; reason = null; try { //check Types namespace WSD.HelloType hello = message.Object; if (hello.Types == null) { reason = Resources.ErrorNoTypes_Text; return(false); } if (!DiscoveryUtils.CheckDeviceHelloType(message, out reason)) { return(false); } if (hello.EndpointReference == null) { reason = Resources.ErrorNoEndpointReference_Text; return(false); } if (hello.Scopes == null) { reason = Resources.ErrorNoScopes_Text; return(false); } if (hello.Scopes.Text == null) { reason = Resources.ErrorNoScopesText_Text; return(false); } //check mandatory scopes string missingScope = DiscoveryUtils.GetMissingMandatoryScope(hello.Scopes.Text); if (!string.IsNullOrEmpty(missingScope)) { reason = string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope); return(false); } //check optional scopes if (scopes != null) { missingScope = DiscoveryUtils.GetMissingScope(hello.Scopes.Text, scopes); if (!string.IsNullOrEmpty(missingScope)) { reason = string.Format(Resources.ErrorMissingScope_Format, missingScope); return(false); } } } catch (Exception e) { reason = e.Message; res = false; } return(res); }
public static string GetDeviceId(WSD.HelloType hello) { string id = string.Empty; if ((hello != null) && (hello.EndpointReference != null) && (hello.EndpointReference.Address != null)) { id = hello.EndpointReference.Address.Value; } return(id); }
public void SendHello() { WSD.HelloType hello = new WSD.HelloType(); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add("dn", DiscoveryUtils.ONVIF_NETWORK_WSDL_URL); hello.EndpointReference = new WSD.EndpointReferenceType(); hello.EndpointReference.Address = new WSD.AttributedURI(); hello.EndpointReference.Address.Value = _uuid; hello.Types = "dn:NetworkVideoTransmitter"; hello.Scopes = new WSD.ScopesType(); hello.Scopes.Text = _scopes; hello.XAddrs = ServiceAddress; byte[] data = SoapBuilder.BuildMessage(hello, Encoding.UTF8, new DiscoveryHeaderBuilder(), namespaces); Send(data); }