private static GeoClient GetGeoClientWithBinding(WcfBindingType wcfBindingType) { GeoClient geoClient = null; // ReSharper disable once SwitchStatementMissingSomeCases switch (wcfBindingType) { case WcfBindingType.NetTcpBinding: const string netTcpEndpoint = "netTcpEndpoint"; geoClient = new GeoClient(netTcpEndpoint); break; case WcfBindingType.BasicHttpBinding: const string basicHttpEndpoint = "basicHttpEndpoint"; geoClient = new GeoClient(basicHttpEndpoint); break; case WcfBindingType.WsHttpBinding: const string wsHttpEndpoint = "wsHttpEndpoint"; geoClient = new GeoClient(wsHttpEndpoint); break; } return(geoClient); }
public WcfService(int port, WcfBindingType bindingType, int itemCount) { _port = port; _bindingType = bindingType; _itemsToSend = Cache.Get <T>().Take(itemCount).ToArray(); _itemCountToRequest = itemCount; }
private void initializeWcfBindingType() { WcfBindingType.Add("Select binding"); foreach (var EnumName in Enum.GetValues(typeof(WcfType))) { WcfBindingType.Add(EnumName.ToString()); } }
private WcfBindingType GetBindingTypeFromRadioButtons() { WcfBindingType wcfBindingType = WcfBindingType.NetTcpBinding; if (NetTcpBindingRadioButton.IsChecked == true) { wcfBindingType = WcfBindingType.NetTcpBinding; } else if (BasicHttpBindingRadioButton.IsChecked == true) { wcfBindingType = WcfBindingType.BasicHttpBinding; } else if (WsHttpBindingRadioButton.IsChecked == true) { wcfBindingType = WcfBindingType.BasicHttpBinding; } return(wcfBindingType); }
private void GetZipCodesButton_Click(object sender, RoutedEventArgs e) { ZipCodesListBox.ItemsSource = null; ZipCodesListBox.Items.Clear(); ErrorMessage2TextBox.Text = ""; string state = StateTextBox.Text; // ReSharper disable once InvertIf if (state != "") { // Alternate constructor //EndpointAddress endpointAddress = new EndpointAddress("net.tcp://localhost:8009/GeoService"); //Binding binding = new NetTcpBinding(); //GeoClient geoClient = new GeoClient(binding, endpointAddress); List <ZipCodeData> zipCodeDataList = null; WcfBindingType wcfBindingType = GetBindingTypeFromRadioButtons(); GeoClient geoClient = GetGeoClientWithBinding(wcfBindingType); try { zipCodeDataList = geoClient.GetZipCodes(state); } catch (FaultException exception) { string message = "Exception: \r\n" + $"Message = {exception.Message} \r\n" + $"Proxy state = {geoClient.State.ToString()}"; ErrorMessage2TextBox.Text = message; } if (zipCodeDataList == null || zipCodeDataList.Count == 0) { ErrorMessage2TextBox.Text = $"No zip code data found for state {state}"; } ZipCodesListBox.ItemsSource = zipCodeDataList; geoClient.Close(); } }
private void GetZipCodeInfoButton_Click(object sender, RoutedEventArgs e) { CityOutputTextBox.Text = ""; StateOutputTextBox.Text = ""; ErrorMessage1TextBox.Text = ""; string zipCode = ZipCodeTextBox.Text; // ReSharper disable once InvertIf if (zipCode != "") { WcfBindingType wcfBindingType = GetBindingTypeFromRadioButtons(); GeoClient geoClient = GetGeoClientWithBinding(wcfBindingType); ZipCodeData zipCodeData = null; try { zipCodeData = geoClient.GetZipCodeInfo(zipCode); } catch (FaultException exception) { string message = "Exception: \r\n" + $"Message = {exception.Message} \r\n" + $"Proxy state = {geoClient.State.ToString()}"; CityOutputTextBox.Text = ""; StateOutputTextBox.Text = ""; ErrorMessage1TextBox.Text = message; } if (zipCodeData != null) { CityOutputTextBox.Text = zipCodeData.City; StateOutputTextBox.Text = zipCodeData.State; } geoClient.Close(); } }
public bool WcfStart(string uri, Type serviceType, string serviceName, Type interfaceType, WcfBindingType bindingType) { // Step 1 of the address configuration procedure: Create a URI to serve as the base address. //Uri baseAddress = new Uri("http://198.168.0.253:1111/ServiceModelSamples/Service"); Uri baseAddress = new Uri(uri); // Step 2 of the hosting procedure: Create ServiceHost //ServiceHost selfHost = new ServiceHost(typeof(TestService), baseAddress); serviceHost = new ServiceHost(serviceType, baseAddress); try { // Step 3 of the hosting procedure: Add a service endpoint. if (bindingType == WcfBindingType.BasicHttpBinding) { serviceHost.AddServiceEndpoint( //typeof(ITest), interfaceType, new BasicHttpBinding(), //"TestService" serviceName); } else if (bindingType == WcfBindingType.WSHttpBinding) { serviceHost.AddServiceEndpoint( //typeof(ITest), interfaceType, new WSHttpBinding(), //"TestService" serviceName); } // Step 4 of the hosting procedure: Enable metadata exchange. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; serviceHost.Description.Behaviors.Add(smb); // Step 5 of the hosting procedure: Start (and then stop) the service. serviceHost.Open(); uriAddress = uri; if (OnSendStatusMSG != null) { OnSendStatusMSG("The service is ready."); } if (OnDoConnect != null) { OnDoConnect(uriAddress); } return(true); } catch (CommunicationException ce) { if (OnSendStatusMSG != null) { OnSendStatusMSG(string.Format("An exception occurred: {0}", ce.Message)); } serviceHost.Abort(); if (OnSendStatusMSG != null) { OnSendStatusMSG("The service is abort."); } Console.WriteLine("WcfStart error!"); return(false); } }
/// <summary> /// Gets the Binding instance according to a Binding type. /// </summary> /// <param name="bindingType">Type of the binding.</param> /// <returns>Instance of Binding.</returns> public static Binding GetBinding(WcfBindingType bindingType) { switch (bindingType) { case WcfBindingType.BasicHttp: return(WcfBinding.BasicHttp); case WcfBindingType.WSHttp: return(WcfBinding.WSHttp); case WcfBindingType.WSDualHttp: return(WcfBinding.WSDualHttp); case WcfBindingType.WSFederationHttp: return(WcfBinding.WSFederationHttp); case WcfBindingType.WS2007Http: return(WcfBinding.WS2007Http); case WcfBindingType.WS2007FederationHttp: return(WcfBinding.WS2007FederationHttp); case WcfBindingType.NetTcp: return(WcfBinding.NetTcp); case WcfBindingType.NetNamedPipe: return(WcfBinding.NetNamedPipe); case WcfBindingType.NetMsmq: return(WcfBinding.NetMsmq); case WcfBindingType.NetPeerTcp: return(WcfBinding.NetPeerTcp); case WcfBindingType.MsmqIntegration: return(WcfBinding.MsmqIntegration); case WcfBindingType.WebHttp: return(WcfBinding.WebHttp); case WcfBindingType.Custom: return(WcfBinding.Custom); #if !__MonoCS__ case WcfBindingType.BasicHttpContext: return(WcfBinding.BasicHttpContext); case WcfBindingType.NetTcpContext: return(WcfBinding.NetTcpContext); case WcfBindingType.WSHttpContext: return(WcfBinding.WSHttpContext); #endif case WcfBindingType.MexHttp: return(WcfBinding.MexHttp); case WcfBindingType.MexHttps: return(WcfBinding.MexHttps); case WcfBindingType.MexTcp: return(WcfBinding.MexTcp); case WcfBindingType.MexNamedPipe: return(WcfBinding.MexNamedPipe); default: try { Binding result = (Binding)Activator.CreateInstance(Type.GetType(bindingType.ToString() + "Binding", true, true)); result.SetTimeout(TimeSpan.FromMinutes(15)); return(result); } catch (Exception e) { InternalLogger.Log(e); return(null); } } }