private static void client_HelloEvent(object obj, DpwsServiceDescription helloEventArgs) { // Print Hello event information Debug.Print(""); Debug.Print("Hello Event:"); Debug.Print("Endpoint Address = " + helloEventArgs.Endpoint.Address.AbsoluteUri); Debug.Print("Types:"); for (int t = 0; t < helloEventArgs.ServiceTypes.Count; ++t) { DpwsServiceType serviceType = helloEventArgs.ServiceTypes[t]; Debug.Print("\tName = " + serviceType.TypeName); Debug.Print("\tNamespace = " + serviceType.NamespaceUri); Debug.Print(""); } Debug.Print("XAddrs:"); foreach (string xaddr in helloEventArgs.XAddrs) Debug.Print("\tTransport Address = " + xaddr); Debug.Print("Metadata Version = " + helloEventArgs.MetadataVersion); }
/// <summary> /// Adds a DpwsServiceDescription to the end of the collection. /// </summary> /// <param name="value"> /// The DpwsServiceDescription element to be added to the end of the collection. /// The value can be null. /// </param> /// <returns> /// The collection index at which the DpwsServiceDescription has been added. /// </returns> public int Add(DpwsServiceDescription value) { lock (m_threadLock) { return(m_serviceDescriptions.Add(value)); } }
/// <summary> /// Determines whether an instance of a specified DpwsServiceDescription is in the collection. /// </summary> /// <param name="item"> /// The DpwsServiceDescription to locate in the collection. The value can be null. /// </param> /// <returns> /// True if DpwsServiceDescription is found in the collection; otherwise, false. /// </returns> public bool Contains(DpwsServiceDescription item) { lock (m_threadLock) { return(m_serviceDescriptions.Contains(item)); } }
private DpwsServiceDescriptions ProcessMatch(DpwsServiceDescription.ServiceDescriptionType type, byte[] response, string messageID, IPEndPoint remoteEP, WsMessageCheck messageCheck) { Microsoft.SPOT.Debug.Assert(type == DpwsServiceDescription.ServiceDescriptionType.ProbeMatch || type == DpwsServiceDescription.ServiceDescriptionType.ResolveMatch); // Parse and build header WsWsaHeader header; XmlReader reader; try { reader = WsSoapMessageParser.ParseSoapMessage(response, out header); } catch { return null; } try { // Make sure this is a probe matches response String headerAction = (type == DpwsServiceDescription.ServiceDescriptionType.ProbeMatch) ? WsWellKnownUri.WsdNamespaceUri + "/ProbeMatches" : WsWellKnownUri.WsdNamespaceUri + "/ResolveMatches"; if (header.Action != headerAction) return null; // Make sure this is not a duplicate probe response if (messageCheck != null) { if (messageCheck.IsDuplicate(header.MessageID, remoteEP.ToString()) == true) { System.Ext.Console.Write("ProbeMatches / ResolveMatches - Duplicate response - " + header.Action + " received"); return null; } } // Make sure the messageID matches the request ID if (header.RelatesTo != messageID) return null; // Process the probe matches #if DEBUG int depth = reader.Depth; #endif DpwsServiceDescriptions matches = new DpwsServiceDescriptions(reader, type); #if DEBUG Microsoft.SPOT.Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader)); #endif return matches; } finally { reader.Close(); } }
public MFTestResults DiscoveryTest_DpwsServiceDescription() { /// <summary> /// 1. Verifies each of the proerties of a ByeEventArgs object /// 2. Sets and re-verifies for simple properties. /// </summary> /// ProtocolVersion v = new ProtocolVersion10(); bool testResult = true; try { WsWsaEndpointRef ep = new WsWsaEndpointRef(new System.Uri(v.AnonymousUri)); DpwsServiceTypes st = new DpwsServiceTypes(); DpwsServiceDescription testBEA = new DpwsServiceDescription(ep, st); Log.Comment("Endpoint"); if (testBEA.Endpoint != null) if (testBEA.Endpoint.GetType() != Type.GetType("Ws.Services.WsaAddressing.WsWsaEndpointRef")) throw new Exception("Endpoint wrong type"); if (testBEA.Endpoint != ep) throw new Exception("Endpoint bad data"); Log.Comment("MetadataVersion"); if (testBEA.MetadataVersion != null) if (testBEA.MetadataVersion.GetType() != Type.GetType("System.String")) throw new Exception("MetadataVersion wrong type"); if (testBEA.MetadataVersion != null) throw new Exception("MetadataVersion bad data"); Log.Comment("XAddrs"); if (testBEA.XAddrs != null) if (testBEA.XAddrs.GetType() != Type.GetType("System.String")) throw new Exception("XAddrs wrong type"); if (testBEA.XAddrs != null) throw new Exception("XAddrs bad data"); Log.Comment("ServiceTypes"); if (testBEA.ServiceTypes != null) if (testBEA.ServiceTypes.GetType() != Type.GetType("Dpws.Client.DpwsServiceTypes")) throw new Exception("ServiceTypes wrong type"); if (testBEA.ServiceTypes.Count != 0) throw new Exception("ServiceTypes bad data"); } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }
private static void client_ByeEvent(object obj, DpwsServiceDescription byeEventArgs) { // Print Bye event information Debug.Print(""); Debug.Print("Bye Event:"); Debug.Print("Endpoint Address = " + byeEventArgs.Endpoint.Address.AbsoluteUri); Debug.Print("XAddrs:"); foreach (string xaddr in byeEventArgs.XAddrs) Debug.Print("\tTransport Address = " + xaddr); }
/// <summary> /// Bye event handler. /// </summary> /// <param name="obj">A reference to the object calling the event handler.</param> /// <param name="byeEventArgs">A DpwsServiceDescription object containing the Bye parameters.</param> /// <remarks>This handler simply displays the Bye message.</remarks> void SimpleServiceClient_ByeEvent(object obj, DpwsServiceDescription byeEventArgs) { Log.Comment("Received Bye Event"); if (m_receivedByeEvent) return; if (byeEventArgs.Endpoint.Address.AbsoluteUri == c_ServiceUrn) { m_receivedByeEvent = true; arBye.Set(); } //Log.Comment("SimpleService received a bye request."); ////Log.Comment("Endpoint address: " + byeEventArgs.Endpoint.Address.AbsoluteUri); ////Log.Comment("Xaddrs: " + byeEventArgs.XAddrs); }
/// <summary> /// Sends a directed Resolve request and parses ResolveMatch response. /// </summary> /// <param name="endpointAddress"> /// A string containing a Dpws devices transport endpoint address. /// For example: http://192.168.0.1:8084/3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <param name="serviceAddress"> /// A string containing the address of a service that will handle the resolve request. /// For example: urn:uuid:2bcdd1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <param name="targetServiceAddress"> /// A string containing the address of a service that can process the resolve request. /// For example: urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <remarks> /// A Resolve is used to resolve the transport address of a know service. The request contains a service /// address aquired from configuration or a previous Resolve or Metadata Get request. /// The DirectedResolve method sends a Http request to the specified endpoint address. /// If the endpoint contains a device with this address receives the request, it must send a unicast ResolveMatches /// response back to the client that made the request. /// </remarks> /// <returns> /// A collection of ResolveMatches objects. A ResolveMatch object contains endpoint details used /// used to locate the actual service on a network and the types supported by the service. /// </returns> public DpwsServiceDescription DirectedResolve(string endpointAddress, string serviceAddress, string targetServiceAddress) { String messageID = ""; WsMessage resolveRequest = BuildResolveRequest(targetServiceAddress, serviceAddress, ref messageID); if (resolveRequest == null) { return(null); } System.Ext.Console.Write(""); System.Ext.Console.Write("Sending Resolve:"); System.Ext.Console.Write(resolveRequest.Body as byte[]); // Create an http client and send the resolve request. Use a WspHttpClient to get an array response. WsHttpClient httpClient = new WsHttpClient(m_version); WsMessage resolveResponse = httpClient.SendRequest(resolveRequest, new Uri(endpointAddress)); DpwsDiscoClientProcessor soapProcessor = new DpwsDiscoClientProcessor(m_version); DpwsServiceDescription resolveMatch = soapProcessor.ProcessResolveMatch(resolveResponse, messageID, null, null); return(resolveMatch); }
/// <summary> /// Sends a directed Resolve request and parses ResolveMatch response. /// </summary> /// <param name="endpointAddress"> /// A string containing a Dpws devices transport endpoint address. /// For example: http://192.168.0.1:8084/3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <param name="serviceAddress"> /// A string containing the address of a service that will handle the resolve request. /// For example: urn:uuid:2bcdd1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <param name="targetServiceAddress"> /// A string containing the address of a service that can process the resolve request. /// For example: urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <remarks> /// A Resolve is used to resolve the transport address of a know service. The request contains a service /// address aquired from configuration or a previous Resolve or Metadata Get request. /// The DirectedResolve method sends a Http request to the specified endpoint address. /// If the endpoint contains a device with this address receives the request, it must send a unicast ResolveMatches /// response back to the client that made the request. /// </remarks> /// <returns> /// A collection of ResolveMatches objects. A ResolveMatch object contains endpoint details used /// used to locate the actual service on a network and the types supported by the service. /// </returns> public DpwsServiceDescription DirectedResolve(string endpointAddress, string serviceAddress, string targetServiceAddress) { String messageID = ""; byte[] resolveRequest = BuildResolveRequest(targetServiceAddress, serviceAddress, ref messageID); if (resolveRequest == null) { return(null); } System.Ext.Console.Write(""); System.Ext.Console.Write("Sending Resolve:"); System.Ext.Console.Write(new string(new UTF8Encoding().GetChars(resolveRequest))); // Create an http client and send the resolve request. Use a WspHttpClient to get an array response. WsHttpClient httpClient = new WsHttpClient(); byte[] resolveResponse = httpClient.SendRequest(resolveRequest, endpointAddress, false, false); DpwsDiscoClientProcessor soapProcessor = new DpwsDiscoClientProcessor(); DpwsServiceDescription resolveMatch = soapProcessor.ProcessResolveMatch(resolveResponse, messageID, null, null); return(resolveMatch); }
internal DpwsServiceDescriptions(XmlReader reader, DpwsServiceDescription.ServiceDescriptionType type) { Microsoft.SPOT.Debug.Assert(type == DpwsServiceDescription.ServiceDescriptionType.ProbeMatch || type == DpwsServiceDescription.ServiceDescriptionType.ResolveMatch); String collectionName, itemName; if (type == DpwsServiceDescription.ServiceDescriptionType.ProbeMatch) { collectionName = "ProbeMatches"; itemName = "ProbeMatch"; } else { collectionName = "ResolveMatches"; itemName = "ResolveMatch"; } reader.ReadStartElement(collectionName, WsWellKnownUri.WsdNamespaceUri); while (reader.IsStartElement(itemName, WsWellKnownUri.WsdNamespaceUri)) { #if DEBUG int depth = reader.Depth; #endif m_serviceDescriptions.Add(new DpwsServiceDescription(reader, type)); #if DEBUG Microsoft.SPOT.Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader)); #endif } if (type == DpwsServiceDescription.ServiceDescriptionType.ResolveMatch && m_serviceDescriptions.Count > 1) { // Per schema, there can only be 1 resolve match throw new XmlException(); } XmlReaderHelper.SkipAllSiblings(reader); // xs:any reader.ReadEndElement(); // collectionName }
/// <summary> /// Method used by the discovery callback methods to raise a Bye event /// </summary> /// <param name="byeEventArgs">A HelloEventArgs object containing hello event details.</param> internal void RaiseByeEvent(DpwsServiceDescription byeEventArgs) { if (ByeEvent != null) { ByeEvent(this, byeEventArgs); } }
/// <summary> /// Method used by the discovery callback methods to raise a Hello event /// </summary> /// <param name="helloEventArgs">A HelloEventArgs object containing hello event details.</param> internal void RaiseHelloEvent(DpwsServiceDescription helloEventArgs) { if (HelloEvent != null) { HelloEvent(this, helloEventArgs); } }
/// <summary> /// Adds a DpwsServiceDescription to the end of the collection. /// </summary> /// <param name="value"> /// The DpwsServiceDescription element to be added to the end of the collection. /// The value can be null. /// </param> /// <returns> /// The collection index at which the DpwsServiceDescription has been added. /// </returns> public int Add(DpwsServiceDescription value) { lock (m_threadLock) { return m_serviceDescriptions.Add(value); } }
internal DpwsServiceDescriptions(XmlReader reader, DpwsServiceDescription.ServiceDescriptionType type, ProtocolVersion v, IPEndPoint remoteEP) { m_threadLock = new object(); m_serviceDescriptions = new ArrayList(); Microsoft.SPOT.Debug.Assert(type == DpwsServiceDescription.ServiceDescriptionType.ProbeMatch || type == DpwsServiceDescription.ServiceDescriptionType.ResolveMatch); String collectionName, itemName; if (type == DpwsServiceDescription.ServiceDescriptionType.ProbeMatch) { collectionName = "ProbeMatches"; itemName = "ProbeMatch"; } else { collectionName = "ResolveMatches"; itemName = "ResolveMatch"; } reader.ReadStartElement(collectionName, v.DiscoveryNamespace); while (reader.IsStartElement(itemName, v.DiscoveryNamespace)) { #if DEBUG int depth = reader.Depth; #endif m_serviceDescriptions.Add(new DpwsServiceDescription(reader, type, v, remoteEP)); #if DEBUG Microsoft.SPOT.Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader)); #endif } if (type == DpwsServiceDescription.ServiceDescriptionType.ResolveMatch && m_serviceDescriptions.Count > 1) { // Per schema, there can only be 1 resolve match throw new XmlException(); } XmlReaderHelper.SkipAllSiblings(reader); // xs:any reader.ReadEndElement(); // collectionName }
/// <summary> /// Determines whether an instance of a specified DpwsServiceDescription is in the collection. /// </summary> /// <param name="item"> /// The DpwsServiceDescription to locate in the collection. The value can be null. /// </param> /// <returns> /// True if DpwsServiceDescription is found in the collection; otherwise, false. /// </returns> public bool Contains(DpwsServiceDescription item) { lock (m_threadLock) { return m_serviceDescriptions.Contains(item); } }
/// <summary> /// Use to send a resolve request to the ws-discovery address and receive a resolve match. /// </summary> /// <param name="message">A byte array containing a the resolve message.</param> /// <param name="messageID"> /// A string containing the message ID of a resolve request. This ID will be used to validate against /// a ResolveMatch received if it don't match, the ResolveMatch is discarded. /// </param> /// <param name="timeout"> /// A DateTime value containing the length of time this request will wait for resolve match. /// until the timeout value has expired. /// </param> /// <returns>A resolve match object.</returns> private DpwsServiceDescription SendResolveRequest(byte[] message, string messageID, long timeout) { WsMessageCheck messageCheck = new WsMessageCheck(); System.Ext.Console.Write(""); System.Ext.Console.Write("Sending Resolve:"); System.Ext.Console.Write(new string(new UTF8Encoding().GetChars(message))); // Create a new UdpClient Socket udpClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint localEP = new IPEndPoint(IPAddress.Any, m_discoResponsePort); udpClient.Bind(localEP); // Very important - Set default multicast interface for the underlying socket byte[] ipBytes = IPAddress.Parse(WsNetworkServices.GetLocalIPV4Address()).GetAddressBytes(); long longIP = (long)((ipBytes[0] + (ipBytes[1] << 0x08) + (ipBytes[2] << 0x10) + (ipBytes[3] << 0x18)) & 0xFFFFFFFF); udpClient.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, (int)longIP); // Random back off implemented as per soap over udp specification // for unreliable multicast message exchange SendWithBackoff(message, udpClient); // Wait for resolve match as long a timeout has not expired DpwsServiceDescription resolveMatch = null; byte[] resolveResponse = new byte[c_MaxUdpPacketSize]; EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0); int responseLength; long endTime = (long)(DateTime.Now.Ticks + (timeout * 10000)); DpwsDiscoClientProcessor soapProcessor = new DpwsDiscoClientProcessor(); while (DateTime.Now.Ticks < endTime) { if (udpClient.Available > 0) { // Since MF sockets does not have an IOControl method catch 10054 to get around the problem // with Upd and ICMP. try { // Wait for response responseLength = udpClient.ReceiveFrom(resolveResponse, c_MaxUdpPacketSize, SocketFlags.None, ref remoteEP); } catch (SocketException se) { if (se.ErrorCode == 10054) { continue; } throw se; } // If we received process resolve match if (responseLength > 0) { System.Ext.Console.Write(""); System.Ext.Console.Write("ResolveMatches Response From: " + ((IPEndPoint)remoteEP).Address.ToString()); System.Ext.Console.Write(new String(System.Text.Encoding.UTF8.GetChars(resolveResponse))); try { resolveMatch = soapProcessor.ProcessResolveMatch(resolveResponse, messageID, (IPEndPoint)remoteEP, messageCheck); if (resolveMatch != null) { break; } } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write(e.Message); System.Ext.Console.Write(""); } } } Thread.Sleep(10); } udpClient.Close(); udpClient = null; // Display results if (resolveMatch == null) { System.Ext.Console.Write("Resolve timed out."); } return(resolveMatch); }
void m_simpleControl_ByeEvent(object obj, DpwsServiceDescription byeEventArgs) { System.Ext.Console.Write(""); System.Ext.Console.Write("SimpleServiceClient received a bye request."); System.Ext.Console.Write("Endpoint address: " + byeEventArgs.Endpoint.Address.ToString()); if (byeEventArgs.XAddrs != null) { System.Ext.Console.Write("Xaddrs: " + byeEventArgs.XAddrs[0]); } System.Ext.Console.Write(""); if (m_deviceSelected.WaitOne(0,false) && m_simpleServiceClient.EndpointAddress == byeEventArgs.Endpoint.Address.ToString()) { m_deviceSelected.Reset(); m_selectedService = null; } }
void m_simpleControl_HelloEvent(object obj, DpwsServiceDescription helloEventArgs) { // If SelectedDevice is set don't do discovery again until Bye event is received if (m_deviceSelected.WaitOne(0, false) || m_inDiscovery) return; m_inDiscovery = true; // Print Hello information try { System.Ext.Console.Write(""); System.Ext.Console.Write("SimpleServiceClient received a hello request."); System.Ext.Console.Write("Endpoint address: " + helloEventArgs.Endpoint.Address.ToString()); CheckConnection(helloEventArgs.ServiceTypes, helloEventArgs.Endpoint.Address.AbsoluteUri); System.Ext.Console.Write("Xaddrs: " + ((helloEventArgs.XAddrs == null) ? "none" : helloEventArgs.XAddrs[0])); System.Ext.Console.Write("Metadata version: " + helloEventArgs.MetadataVersion); } finally { m_inDiscovery = false; } }
/// <summary> /// Use to send a resolve request to the ws-discovery address and receive a resolve match. /// </summary> /// <param name="message">A byte array containing a the resolve message.</param> /// <param name="messageID"> /// A string containing the message ID of a resolve request. This ID will be used to validate against /// a ResolveMatch received if it don't match, the ResolveMatch is discarded. /// </param> /// <param name="timeout"> /// A DateTime value containing the length of time this request will wait for resolve match. /// until the timeout value has expired. /// </param> /// <returns>A resolve match object.</returns> private DpwsServiceDescription SendResolveRequest(byte[] message, string messageID, long timeout) { WsMessageCheck messageCheck = new WsMessageCheck(); DpwsServiceDescription resolveMatch = null; System.Ext.Console.Write(""); System.Ext.Console.Write("Sending Resolve:"); System.Ext.Console.Write(message); // Create a new UdpClient using (Socket udpClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { uint ipLocal = WsNetworkServices.GetLocalIPV4AddressValue(); IPAddress localIP = IPAddress.Parse(WsNetworkServices.GetLocalIPV4Address()); IPEndPoint localEP = new IPEndPoint(localIP, 0); // Very important - Set default multicast interface for the underlying socket udpClient.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, (int)ipLocal); udpClient.ReceiveTimeout = (int)timeout; udpClient.Bind(localEP); // Random back off implemented as per soap over udp specification // for unreliable multicast message exchange Thread th = SendWithBackoff(message, udpClient); // Wait for resolve match as long a timeout has not expired byte[] resolveResponse = new byte[c_MaxUdpPacketSize]; EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0); int responseLength; DpwsDiscoClientProcessor soapProcessor = new DpwsDiscoClientProcessor(m_version); while (true) { // Since MF sockets does not have an IOControl method catch 10054 to get around the problem // with Upd and ICMP. try { // Wait for response responseLength = udpClient.ReceiveFrom(resolveResponse, c_MaxUdpPacketSize, SocketFlags.None, ref remoteEP); } catch (SocketException se) { if ((SocketError)se.ErrorCode == SocketError.ConnectionReset) { Thread.Sleep(100); continue; } if ((SocketError)se.ErrorCode == SocketError.TimedOut) { break; } throw se; } // If we received process resolve match if (responseLength > 0) { System.Ext.Console.Write("ResolveMatches Response From: " + ((IPEndPoint)remoteEP).Address.ToString()); System.Ext.Console.Write(resolveResponse); try { WsWsaHeader header = new WsWsaHeader(); XmlReader reader = WsSoapMessageParser.ParseSoapMessage(resolveResponse, ref header, m_version); WsMessage msg = new WsMessage(header, null, WsPrefix.Wsdp); msg.Reader = reader; resolveMatch = soapProcessor.ProcessResolveMatch(msg, messageID, (IPEndPoint)remoteEP, messageCheck); if (resolveMatch != null) { break; } } catch (Exception e) { System.Ext.Console.Write(e.Message); } } } th.Join(); } // Display results if (resolveMatch == null) { System.Ext.Console.Write("Resolve timed out."); } return(resolveMatch); }
void SimpleServiceClient_HelloEvent(object obj, DpwsServiceDescription helloEventArgs) { m_receivedHelloEvent = true; DpwsMetadata m_mexDetails = null; try { // Print Hello information //Log.Comment(""); //Log.Comment("SimpleService received a hello request."); ////Log.Comment("Endpoint address: " + helloEventArgs.Endpoint.Address.AbsoluteUri); string types = ""; int count = helloEventArgs.ServiceTypes.Count; for (int i = 0; i < count; i++) { DpwsServiceType type = helloEventArgs.ServiceTypes[i]; types += "NamespaceUri: " + type.NamespaceUri + " " + "TypeName: " + type.TypeName + "\n"; } ////Log.Comment("Types: " + types); if (helloEventArgs.XAddrs != null) { foreach (String xaddr in helloEventArgs.XAddrs) { ////Log.Comment("Xaddrs: " + xaddr); } } ////Log.Comment("Metadata version: " + helloEventArgs.MetadataVersion); ////Log.Comment(""); // Probe for services. For each valid probe match, print service information. DpwsServiceType searchType = new DpwsServiceType("SimpleService", "http://schemas.example.org/SimpleService"); DpwsServiceTypes searchTypes = new DpwsServiceTypes(); searchTypes.Add(searchType); // Accept the first 10 found within the first 10 seconds DpwsServiceDescriptions probeMatches = this.DiscoveryClient.Probe(searchTypes, 1, 10000); // retry if (probeMatches.Count == 0) { probeMatches = this.DiscoveryClient.Probe(searchTypes, 1, 10000); } if (probeMatches != null) { // Print the probe match information ////Log.Comment("**********************"); ////Log.Comment("ProbeMatches received: " + probeMatches.Count); int probeMatchCount = probeMatches.Count; for (int i = 0; i < probeMatchCount; i++) { DpwsServiceDescription probeMatch = probeMatches[i]; ////Log.Comment(""); ////Log.Comment("ProbeMatch:"); ////Log.Comment(" Endpoint Address = " + probeMatch.Endpoint.Address.AbsoluteUri); ////Log.Comment(" Types:"); PrintServiceTypes(probeMatch.ServiceTypes); //////Log.Comment(" Xaddrs:"); //foreach (string xaddr in probeMatch.XAddrs) // //Log.Comment(" TransportAddress = " + xaddr); ////Log.Comment(" Metadata Version = " + probeMatch.MetadataVersion); // Resolve this endpoint DpwsServiceDescription resolveMatch = this.DiscoveryClient.Resolve(probeMatch.Endpoint.Address.AbsoluteUri, 10000); if (resolveMatch != null) { // Print resolve match information ////Log.Comment(""); ////Log.Comment("ResolveMatch:"); ////Log.Comment(" Endpoint Address = " + resolveMatch.Endpoint.Address.AbsoluteUri); ////Log.Comment(" Types:"); PrintServiceTypes(resolveMatch.ServiceTypes); ////Log.Comment(" Xaddrs:"); //foreach (string xaddr in resolveMatch.XAddrs) // //Log.Comment(" TransportAddress = " + xaddr); //Log.Comment(" Metadata Version = " + resolveMatch.MetadataVersion); // For each Xaddr, get metadata foreach (string xaddr in resolveMatch.XAddrs) { // Call Get m_mexDetails = this.MexClient.Get(xaddr); if (m_mexDetails == null) { ////Log.Comment("Get failed. Address: " + xaddr); } else { m_getMex = true; // Display metadata information ////Log.Comment(" Metadata:"); ////Log.Comment(" ThisModel:"); ////Log.Comment(" Manufacturer: " + m_mexDetails.ThisModel.Manufacturer); ////Log.Comment(" ManufacturerUrl: " + m_mexDetails.ThisModel.ManufacturerUrl); ////Log.Comment(" ModelName: " + m_mexDetails.ThisModel.ModelName); ////Log.Comment(" ModelNumber: " + m_mexDetails.ThisModel.ModelNumber); ////Log.Comment(" ModelUrl: " + m_mexDetails.ThisModel.ModelUrl); ////Log.Comment(" PresentationUrl: " + m_mexDetails.ThisModel.PresentationUrl); ////Log.Comment(" ThisDevice:"); ////Log.Comment(" FirmwareVersion: " + m_mexDetails.ThisDevice.FirmwareVersion); ////Log.Comment(" FriendlyName: " + m_mexDetails.ThisDevice.FriendlyName); ////Log.Comment(" SerialNumber: " + m_mexDetails.ThisDevice.SerialNumber); if (m_mexDetails.Relationship.Host != null) { ////Log.Comment(" Host:"); ////Log.Comment(" Service ID: " + m_mexDetails.Relationship.Host.ServiceID); ////Log.Comment(" Address: " + m_mexDetails.Relationship.Host.EndpointRefs[0].Address.AbsoluteUri); ////Log.Comment(" Types:"); PrintServiceTypes(m_mexDetails.Relationship.Host.ServiceTypes); } if (m_mexDetails.Relationship.HostedServices != null) { ////Log.Comment(" HostedServices:"); int hostedServiceCount = m_mexDetails.Relationship.HostedServices.Count; for (int j = 0; j < hostedServiceCount; j++) { DpwsMexService hostedService = m_mexDetails.Relationship.HostedServices[j]; ////Log.Comment(" Service ID: " + hostedService.ServiceID); ////Log.Comment(" Address: " + hostedService.EndpointRefs[0].Address.AbsoluteUri); ////Log.Comment(" Types:"); PrintServiceTypes(hostedService.ServiceTypes); } } } } if (m_mexDetails != null) { // Look for the SimpleService in the HostedServices collection, create an HTTP // client, call TwoWayRequest on the service endpoint, and display the result. int hostedServiceCount = m_mexDetails.Relationship.HostedServices.Count; for (int j = 0; j < hostedServiceCount; j++) { DpwsMexService hostedService = m_mexDetails.Relationship.HostedServices[j]; if (hostedService.ServiceTypes["SimpleService"] != null) // found a SimpleService endpoint { string endpointAddress = hostedService.EndpointRefs[0].Address.AbsoluteUri; ////Log.Comment(""); ////Log.Comment("Calling TwoWayRequest at endpoint: " + endpointAddress); // Create HttpClient and send request int x = 150; int y = 180; byte[] TwoWayRequest = Build2wayRequest(x, y, endpointAddress); //Log.Comment(new String(System.Text.Encoding.UTF8.GetChars(TwoWayRequest))); //DpwsHttpClient httpClient = new DpwsHttpClient(); //DpwsSoapResponse response = httpClient.SendRequest(TwoWayRequest, endpointAddress, false, false); WsHttpClient httpClient = new WsHttpClient(m_version); WsMessage response = httpClient.SendRequest(new WsMessage(null, TwoWayRequest, WsPrefix.Wsdp), new Uri(endpointAddress)); if (response != null) // got a response { try { int sum = Parse2WayResponse(response.Header, response.Reader); //Log.Comment(""); //Log.Comment("Received sum of " + sum.ToString() + " from " + endpointAddress); if ((x + y) == sum) m_twoWay = true; } finally { response.Reader.Close(); } } } } } //Log.Comment(""); } } } } finally { } if (m_mexDetails != null) { arHello.Set(); } }