/// <summary> /// Create new instance of <see cref="Microsoft.Samples.NLayerApp.Presentation.Windows.WPF.ServiceAgents.Proxies.MainModuleicrosoft.Samples.NLayerApp.Presentation.Windows.WPF.ServiceAgents.Proxies.MainModule.IMainModuleService"/> /// instance with a configuration of uri, via behaviors, etc /// </summary> /// <returns>New instance of <see cref="Microsoft.Samples.NLayerApp.Presentation.Windows.WPF.ServiceAgents.Proxies.MainModuleicrosoft.Samples.NLayerApp.Presentation.Windows.WPF.ServiceAgents.Proxies.MainModule.IMainModuleService"/> /// </returns> public static IMainModuleService GetMainModuleService() { //This method encapsulate discover end point, set via behaviors, security credentials initialization //and other configuration params //if discovery services is enabled in configuration file string discoveryValue = ConfigurationManager.AppSettings["discovery_wcf_services"]; bool discoveryResult; if (!string.IsNullOrEmpty(discoveryValue) && !string.IsNullOrWhiteSpace(discoveryValue) && Boolean.TryParse(discoveryValue,out discoveryResult) && discoveryResult) { //for more information about DynamicEndpoint and WS-Discovery see //http://msdn.microsoft.com/en-us/library/dd288697.aspx //http://geeks.ms/blogs/unai/archive/2009/12/21/wcf-4-0-ws-discovery-y-dynamicendpoint.aspx DynamicEndpoint endpoint = new DynamicEndpoint(ContractDescription.GetContract(typeof(IMainModuleService)), new WS2007HttpBinding()); return new MainModuleServiceClient(endpoint); } else return new MainModuleServiceClient(); }
public void DefaultValues () { var cd = ContractDescription.GetContract (typeof (ITestService)); var binding = new BasicHttpBinding (); var de = new DynamicEndpoint (cd, binding); Assert.AreEqual (DiscoveryClientBindingElement.DiscoveryEndpointAddress, de.Address, "#1"); var fc = de.FindCriteria; Assert.IsNotNull (fc, "#2"); Assert.AreEqual (1, fc.ContractTypeNames.Count, "#2-2"); Assert.AreEqual (0, fc.Scopes.Count, "#2-3"); Assert.AreEqual (0, fc.Extensions.Count, "#2-4"); var dep = de.DiscoveryEndpointProvider; Assert.IsNotNull (dep, "#3"); var dise = dep.GetDiscoveryEndpoint (); TestDiscoveryEndpoint (dise); Assert.IsNotNull (de.Contract, "#11"); // for ITestService Assert.AreEqual ("http://tempuri.org/", de.Contract.Namespace, "#11-2"); Assert.AreEqual ("ITestService", de.Contract.Name, "#11-3"); Assert.IsNotNull (de.Binding, "#12"); // Custom{DiscoveryClient|BasicHttpBinding-elements} Assert.IsNotNull (de.Binding.CreateBindingElements ().FirstOrDefault (be => be is DiscoveryClientBindingElement), "#12-2"); Assert.IsNotNull (de.Binding.CreateBindingElements ().FirstOrDefault (be => be is HttpTransportBindingElement), "#12-3"); Assert.IsNotNull (de.Address, "#13"); Assert.AreEqual (DiscoveryClientBindingElement.DiscoveryEndpointAddress, de.Address, "#13-2"); Assert.AreEqual (DiscoveryClientBindingElement.DiscoveryEndpointAddress.Uri, de.ListenUri, "#14"); Assert.AreEqual (0, de.Behaviors.Count, "#15"); }
internal static ITicketingCallBack GetProxy(bool discovery) { if (_chf == null) { lock (typeof(CallBackChannelFactory)) { if (_chf == null) _chf = new ChannelFactory<Contracts.ITicketingCallBack>("BridgeCallBackEP"); } } if (discovery) { // Create a DynamicEndpoint which will discover endpoints when the client is opened. // By default, the contract specified in DynamicEndpoint will be used as the FindCriteria // and UdpDiscoveryEndpoint will be used to send Probe message DynamicEndpoint dynamicEndpoint = new DynamicEndpoint( ContractDescription.GetContract(typeof(ITicketingCallBack)), new NetMsmqBinding()); return _chf.CreateChannel(dynamicEndpoint.Address); } else { return _chf.CreateChannel(); } }
public void DefaultValues () { var cd = ContractDescription.GetContract (typeof (ITestService)); var binding = new BasicHttpBinding (); var de = new DynamicEndpoint (cd, binding); Assert.AreEqual (DiscoveryClientBindingElement.DiscoveryEndpointAddress, de.Address, "#1"); var fc = de.FindCriteria; Assert.IsNotNull (fc, "#2"); Assert.AreEqual (1, fc.ContractTypeNames.Count, "#2-2"); Assert.AreEqual (0, fc.Scopes.Count, "#2-3"); Assert.AreEqual (0, fc.Extensions.Count, "#2-4"); Assert.IsNotNull (de.DiscoveryEndpointProvider, "#3"); }
public static void Main() { try { DynamicEndpoint dynamicEndpoint = new DynamicEndpoint(ContractDescription.GetContract(typeof(ICalculatorService)), new NetTcpBinding()); Uri redmondScope = new Uri("net.tcp://Microsoft.Samples.Discovery/RedmondLocation"); Uri seattleScope = new Uri("net.tcp://Microsoft.Samples.Discovery/SeattleLocation"); Uri portlandScope = new Uri("net.tcp://Microsoft.Samples.Discovery/PortlandLocation"); dynamicEndpoint.FindCriteria.Scopes.Add(redmondScope); dynamicEndpoint.FindCriteria.Scopes.Add(seattleScope); dynamicEndpoint.FindCriteria.Scopes.Add(portlandScope); // Specify the custom ScopeMatchBy dynamicEndpoint.FindCriteria.ScopeMatchBy = new Uri("net.tcp://Microsoft.Samples.Discovery/ORExactMatch"); CalculatorServiceClient client = new CalculatorServiceClient(dynamicEndpoint); Console.WriteLine("Discovering CalculatorService."); Console.WriteLine("Looking for a Calculator Service that matches either of the scopes:"); Console.WriteLine(" " + redmondScope); Console.WriteLine(" " + seattleScope); Console.WriteLine(" " + portlandScope); Console.WriteLine(); double value1 = 1023; double value2 = 1534; double value3 = 2342; // Call the Add service operation. double result = client.Add(value1, value2); Console.WriteLine("Adding({0}, {1}) = {2}", value1, value2, result); // Call the Subtract service operation. result = client.Subtract(value3, value2); Console.WriteLine("Subtracting ({0}, {1}) = {2}", value3, value2, result); //Closing the client gracefully closes the connection and cleans up resources client.Close(); } catch (EndpointNotFoundException) { Console.WriteLine("Unable to connect to the calculator service because a valid endpoint was not found."); } Console.WriteLine("Press <ENTER> to exit."); Console.ReadLine(); }
public static void Main() { // Create a DynamicEndpoint which will discover endpoints when the client is opened. // By default, the contract specified in DynamicEndpoint will be used as the FindCriteria // and UdpDiscoveryEndpoint will be used to send Probe message DynamicEndpoint dynamicEndpoint = new DynamicEndpoint( ContractDescription.GetContract(typeof(ICalculatorService)), new WSHttpBinding()); try { InvokeCalculatorService(dynamicEndpoint); } catch (EndpointNotFoundException) { Console.WriteLine("The DynamicEndpoint could not find an endpoint to connect to."); } Console.WriteLine("Press <ENTER> to exit."); Console.ReadLine(); }
internal static ITicketingServiceOneWay GetProxy(bool discovery) { if (_chf == null) { lock (typeof(TicketingServiceOneWayProxyFactory)) { if (_chf == null) _chf = new ChannelFactory<ITicketingServiceOneWay>("QueuedTicketingEP"); } } if (discovery) { // TODO: Ex6 - Use a dynamic endpoint to find the ticketing service DynamicEndpoint dynamicEndpoint = new DynamicEndpoint(ContractDescription.GetContract( typeof(ITicketingServiceOneWay)), new NetMsmqBinding()); return _chf.CreateChannel(dynamicEndpoint.Address); } else { return _chf.CreateChannel(); } }