private void btnSetDiscoveryMode_Click(object sender, EventArgs e) { try { DiscoveryMode mode = (DiscoveryMode)comboBoxDiscoveryMode.SelectedValue; DeviceClient service = GetService(); if (cbTrace.Checked) { if (cbLowLevelTrace.Checked) { System.ServiceModel.Channels.CustomBinding cb = (System.ServiceModel.Channels.CustomBinding)service.Endpoint.Binding; CustomTextMessageBindingElement ctmbe = (CustomTextMessageBindingElement)cb.Elements[0]; string value = "Discoverrable"; string path = "/s:Envelope/s:Body/onvif:SetDiscoveryMode/onvif:DiscoveryMode"; Dictionary <string, string> namespaces = new Dictionary <string, string>(); namespaces.Add("s", "http://www.w3.org/2003/05/soap-envelope"); namespaces.Add("onvif", "http://www.onvif.org/ver10/device/wsdl"); ctmbe.AddBreakingBehaviour(new BreakingBehaviour(path, value, namespaces)); } } service.SetDiscoveryMode(mode); ShowStatusMessage("Done"); service.Close(); } catch (Exception ex) { ShowStatusMessage("Operation failed"); TraceException(ex); MessageBox.Show(ex.Message); } }
public static OmnitureWebServicePortTypeClient GetClient(string username, string secret, string endpoint) { var httpsTransportBindingElement = new HttpsTransportBindingElement { UseDefaultWebProxy = false, MaxReceivedMessageSize = 2147483647 }; var transportSecurityBindingElement = new TransportSecurityBindingElement(); transportSecurityBindingElement.EndpointSupportingTokenParameters.SignedEncrypted.Add(new SecurityTokenParameters()); transportSecurityBindingElement.IncludeTimestamp = false; var customTextMessageBindingElement = new CustomTextMessageBindingElement { MessageVersion = MessageVersion.Soap11 }; var bindingElements = new List <BindingElement> { transportSecurityBindingElement, customTextMessageBindingElement, httpsTransportBindingElement }; Binding customBinding = new CustomBinding(bindingElements.ToArray()); var endpointAddress = new EndpointAddress(endpoint); var clientCredential = new ClientCredentials(new Info(username, secret)); var omnitureWebServicePortTypeClient = new OmnitureWebServicePortTypeClient(customBinding, endpointAddress); omnitureWebServicePortTypeClient.Endpoint.Behaviors.Remove(typeof(System.ServiceModel.Description.ClientCredentials)); omnitureWebServicePortTypeClient.Endpoint.Behaviors.Add(clientCredential); return(omnitureWebServicePortTypeClient); }
DeviceClient GetService() { DeviceClient service = new DeviceClient(); service.Endpoint.Address = new EndpointAddress(tbAddress.Text); System.ServiceModel.Channels.CustomBinding cb = (System.ServiceModel.Channels.CustomBinding)service.Endpoint.Binding; if (cbHttps.Checked) { HttpsTransportBindingElement elem = new HttpsTransportBindingElement(); cb.Elements[1] = elem; } if (cbTrace.Checked) { if (cbLowLevelTrace.Checked) { CustomTextMessageBindingElement ctmbe = new CustomTextMessageBindingElement(); cb.Elements[0] = ctmbe; ctmbe.SetListener(_textBoxListener); } else { service.Endpoint.Behaviors.Add(new TraceBehavior(_textBoxListener)); } } return(service); }
/// <summary> /// Try reconnect to server. /// </summary> private void TryReConnect() { var baseAddress = new Uri(string.Format("net.tcp://{0}:{1}/AutoCompleteWcfService", this._host, this._port)); var bindingElements = new List <BindingElement>(); var httpBindingElement = new TcpTransportBindingElement(); var textBindingElement = new CustomTextMessageBindingElement("us-ascii"); bindingElements.Add(textBindingElement); bindingElements.Add(httpBindingElement); var binding = new CustomBinding(bindingElements); var adress = new EndpointAddress(baseAddress); this.client = new AutoCompleteWcfServiceClient(binding, adress); try { this.client.Open(); } catch (ChannelTerminatedException) { } catch (EndpointNotFoundException) { } catch (ServerTooBusyException) { } catch (TimeoutException) { } catch (CommunicationException) { } }
public static OmnitureWebServicePortTypeClient GetClient( string username, string secret, string endpoint ) { var httpsTransportBindingElement = new HttpsTransportBindingElement { UseDefaultWebProxy = false, MaxReceivedMessageSize = 2147483647 }; var transportSecurityBindingElement = new TransportSecurityBindingElement(); transportSecurityBindingElement.EndpointSupportingTokenParameters.SignedEncrypted.Add( new SecurityTokenParameters() ); transportSecurityBindingElement.IncludeTimestamp = false; var customTextMessageBindingElement = new CustomTextMessageBindingElement { MessageVersion = MessageVersion.Soap11 }; var bindingElements = new List<BindingElement> { transportSecurityBindingElement, customTextMessageBindingElement, httpsTransportBindingElement }; Binding customBinding = new CustomBinding( bindingElements.ToArray() ); var endpointAddress = new EndpointAddress( endpoint ); var clientCredential = new ClientCredentials( new Info( username, secret ) ); var omnitureWebServicePortTypeClient = new OmnitureWebServicePortTypeClient( customBinding, endpointAddress ); omnitureWebServicePortTypeClient.Endpoint.Behaviors.Remove( typeof( System.ServiceModel.Description.ClientCredentials ) ); omnitureWebServicePortTypeClient.Endpoint.Behaviors.Add( clientCredential ); return omnitureWebServicePortTypeClient; }
/// <inheritdoc /> protected override BindingElement CreateBindingElement() { var binding = new CustomTextMessageBindingElement(); this.ApplyConfiguration(binding); return(binding); }
private ITestService CreateSoap11Iso88591Client() { var transport = new HttpTransportBindingElement(); var textencoding = new CustomTextMessageBindingElement("iso-8859-1", "text/xml", MessageVersion.Soap11); var binding = new CustomBinding(textencoding, transport); var endpoint = new EndpointAddress(new Uri(string.Format("http://{0}:5050/WSA11ISO88591Service.svc", "localhost"))); var channelFactory = new ChannelFactory <ITestService>(binding, endpoint); var serviceClient = channelFactory.CreateChannel(); return(serviceClient); }
/// <summary> /// The start server. /// </summary> /// <param name="inputFile"> /// The input file (vocabulary). /// </param> /// <param name="port"> /// The server port. /// </param> public void Run(string inputFile, int port) { this.reader.AddVocabulary(File.OpenText(inputFile)); var baseAddress = new Uri(string.Format("net.tcp://0.0.0.0:{0}/AutoCompleteWcfService", port)); this.selfHost = new ServiceHost(typeof(AutoCompleteWcfService), baseAddress); try { var bindingElements = new List <BindingElement>(); var tcpTransportBindingElement = new TcpTransportBindingElement(); var textBindingElement = new CustomTextMessageBindingElement("us-ascii"); bindingElements.Add(textBindingElement); bindingElements.Add(tcpTransportBindingElement); var binding = new CustomBinding(bindingElements); binding.ReceiveTimeout = new TimeSpan(0, 0, 120, 0); this.selfHost.AddServiceEndpoint(typeof(IAutoCompleteWcfService), binding, string.Empty); var smb = new ServiceMetadataBehavior { HttpGetEnabled = false, HttpsGetEnabled = false }; this.selfHost.Description.Behaviors.Add(smb); var mexBinding = MetadataExchangeBindings.CreateMexTcpBinding(); this.selfHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "mex"); this.selfHost.AddDependencyInjectionBehavior <IAutoCompleteWcfService>(ServiceLocator.GetContainer()); var throttleBehavior = new ServiceThrottlingBehavior { MaxConcurrentCalls = this.Throughput, MaxConcurrentInstances = 20, MaxConcurrentSessions = this.Throughput, }; this.selfHost.Description.Behaviors.Add(throttleBehavior); this.selfHost.Open(); Logger.Info("The WCF server is ready. Listening {0} port ...", port); Logger.Info("Press <ENTER> to terminate server."); } catch (CommunicationException ce) { Logger.Error("An exception occurred: {0}", ce.Message); this.selfHost.Abort(); } }
CustomBinding ServiceBinding() { if (_binding == null) { _binding = new CustomBinding(); MessageVersion version = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); CustomTextMessageBindingElement ctmbe = new CustomTextMessageBindingElement("utf-8", "application/soap+xml", version); ctmbe.AddController(_logger); _binding.Elements.Add(ctmbe); HttpTransportBindingElement htbe = new HttpTransportBindingElement(); //htbe.AuthenticationScheme = System.Net.AuthenticationSchemes.Digest; _binding.Elements.Add(htbe); } return(_binding); }
protected override BindingElement CreateBindingElement() { CustomTextMessageBindingElement binding = new CustomTextMessageBindingElement(); this.ApplyConfiguration(binding); return binding; }
CustomTextMessageBindingElement(CustomTextMessageBindingElement binding) : this(binding.Encoding, binding.MediaType, binding.MessageVersion) { this.readerQuotas = new XmlDictionaryReaderQuotas(); binding.ReaderQuotas.CopyTo(this.readerQuotas); }
/// <summary> /// Returns a custom wcf binding that will create a SOAP request /// compatible with the Simple Order API Service /// </summary> protected static CustomBinding getWCFCustomBinding() { //Setup custom binding with HTTPS + Body Signing CustomBinding currentBinding = new CustomBinding(); //Sign the body AsymmetricSecurityBindingElement asec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10); asec.SetKeyDerivation(false); asec.IncludeTimestamp = false; asec.EnableUnsecuredResponse = true; asec.SecurityHeaderLayout = SecurityHeaderLayout.Lax; //Use custom encoder to strip unsigned timestamp in response CustomTextMessageBindingElement textBindingElement = new CustomTextMessageBindingElement(); //Setup https transport HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement(); httpsTransport.RequireClientCertificate = true; httpsTransport.AuthenticationScheme = AuthenticationSchemes.Anonymous; httpsTransport.MaxReceivedMessageSize = 2147483647; httpsTransport.UseDefaultWebProxy = false; //Setup Proxy if needed if (mProxy != null) { WebRequest.DefaultWebProxy = mProxy; httpsTransport.UseDefaultWebProxy = true; } //Bind in order (Security layer, message layer, transport layer) currentBinding.Elements.Add(asec); currentBinding.Elements.Add(textBindingElement); currentBinding.Elements.Add(httpsTransport); return currentBinding; }