static void Main(string[] args) { try { //建立和发送端相同的通道栈 BindingElement[] bindingElements = new BindingElement[3]; bindingElements[0] = new TextMessageEncodingBindingElement();//文本编码 //oneWayBindingElement() 传输通道支持数据报模式 bindingElements[1] = new OneWayBindingElement(); bindingElements[2] = new NamedPipeTransportBindingElement();//命名管道 CustomBinding binding = new CustomBinding(bindingElements); //建立ChannelListner倾听者,接收数据 IChannelListener <IInputChannel> listener = binding.BuildChannelListener <IInputChannel>(new Uri("net.pipe://localhost/InputService"), new BindingParameterCollection()); listener.Open();//打开ChannelListner IInputChannel inputChannel = listener.AcceptChannel(); //创建IInputChannel inputChannel.Open(); //打开IInputChannel Console.WriteLine("开始接受消息.."); Message message = inputChannel.Receive(); //接受并打印 Console.WriteLine($"接收一条消息,action为{message.Headers.Action},Body为{message.GetBody<string>()}"); message.Close(); //关闭消息 inputChannel.Close(); //关闭通道 listener.Close(); //关闭监听器 Console.Read(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { Console.Read(); } }
public AclSecuredNamedPipeTransportBindingElement(NamedPipeTransportBindingElement inner) : base(inner) { if (inner is AclSecuredNamedPipeTransportBindingElement) { _allowedUsers = new List <SecurityIdentifier>(((AclSecuredNamedPipeTransportBindingElement)inner)._allowedUsers); } }
protected internal override void InitializeFrom(BindingElement bindingElement) { base.InitializeFrom(bindingElement); NamedPipeTransportBindingElement element = (NamedPipeTransportBindingElement)bindingElement; this.ConnectionPoolSettings.InitializeFrom(element.ConnectionPoolSettings); }
/// <summary> /// 功能:添加元数据交换终结点 /// </summary> private void AddAllMexEndPoint() { foreach (Uri baseAddress in BaseAddresses) { BindingElement beTemp = null; switch (baseAddress.Scheme.Trim().ToLower()) { case "net.tcp": beTemp = new TcpTransportBindingElement(); break; case "net.pipe": beTemp = new NamedPipeTransportBindingElement(); break; case "http": beTemp = new HttpTransportBindingElement(); break; case "https": beTemp = new HttpsTransportBindingElement(); break; } if (null != beTemp) { Binding bdTemp = new CustomBinding(beTemp); AddServiceEndpoint(typeof(IMetadataExchange), bdTemp, "Mex"); } } }
public void ExportPolicy () { ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement (); binding_element.ChannelInitializationTimeout = TimeSpan.FromSeconds (3); binding_element.ConnectionBufferSize = binding_element.ConnectionBufferSize / 2; binding_element.HostNameComparisonMode = HostNameComparisonMode.WeakWildcard; binding_element.ManualAddressing = !binding_element.ManualAddressing; binding_element.MaxBufferSize = binding_element.MaxBufferSize / 2; binding_element.MaxBufferPoolSize = binding_element.MaxBufferPoolSize / 2; binding_element.MaxOutputDelay = TimeSpan.FromSeconds (3); binding_element.MaxPendingAccepts = 3; binding_element.MaxPendingConnections = 15; binding_element.MaxReceivedMessageSize = binding_element.MaxReceivedMessageSize / 2; binding_element.TransferMode = TransferMode.Streamed; // Causes an assertion with Streamed* values IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension; PolicyConversionContext conversion_context = new CustomPolicyConversionContext (); export_extension.ExportPolicy (new WsdlExporter (), conversion_context); PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions (); BindingElementCollection binding_elements = conversion_context.BindingElements; Assert.AreEqual (3, binding_assertions.Count, "#A0"); Assert.AreEqual (0, binding_elements.Count, "#A1"); // msf:Streamed XmlNode streamed_node = FindAssertion (binding_assertions, "msf:Streamed"); Assert.AreEqual (true, streamed_node != null, "#B0"); Assert.AreEqual ("Streamed", streamed_node.LocalName, "#B1"); Assert.AreEqual ("http://schemas.microsoft.com/ws/2006/05/framing/policy", streamed_node.NamespaceURI, "#B2"); Assert.AreEqual (String.Empty, streamed_node.InnerText, "#B3"); Assert.AreEqual (0, streamed_node.Attributes.Count, "#B4"); Assert.AreEqual (0, streamed_node.ChildNodes.Count, "#B5"); }
private static CustomBinding CreateNamedPipeBinding() { CustomBinding binding = new CustomBinding("MetadataExchangeNamedPipeBinding", "http://schemas.microsoft.com/ws/2005/02/mex/bindings", new BindingElement[0]); NamedPipeTransportBindingElement item = new NamedPipeTransportBindingElement(); binding.Elements.Add(item); return binding; }
public void ExportPolicyDefault () { ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement (); IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension; PolicyConversionContext conversion_context = new CustomPolicyConversionContext (); export_extension.ExportPolicy (new WsdlExporter (), conversion_context); PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions (); BindingElementCollection binding_elements = conversion_context.BindingElements; Assert.AreEqual (2, binding_assertions.Count, "#A0"); Assert.AreEqual (0, binding_elements.Count, "#A1"); // wsaw:UsingAddressing XmlNode using_addressing_node = FindAssertion (binding_assertions, "wsaw:UsingAddressing"); Assert.AreEqual (true, using_addressing_node != null, "#B0"); Assert.AreEqual ("UsingAddressing", using_addressing_node.LocalName, "#B1"); Assert.AreEqual ("http://www.w3.org/2006/05/addressing/wsdl", using_addressing_node.NamespaceURI, "#B2"); Assert.AreEqual (String.Empty, using_addressing_node.InnerText, "#B3"); Assert.AreEqual (0, using_addressing_node.Attributes.Count, "#B4"); Assert.AreEqual (0, using_addressing_node.ChildNodes.Count, "#B5"); // msb:BinaryEncoding XmlNode binary_encoding_node = FindAssertion (binding_assertions, "msb:BinaryEncoding"); Assert.AreEqual (true, binary_encoding_node != null, "#C0"); Assert.AreEqual ("BinaryEncoding", binary_encoding_node.LocalName, "#C1"); Assert.AreEqual ("http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1", binary_encoding_node.NamespaceURI, "#C2"); Assert.AreEqual (String.Empty, binary_encoding_node.InnerText, "#C3"); Assert.AreEqual (0, binary_encoding_node.Attributes.Count, "#C4"); Assert.AreEqual (0, binary_encoding_node.ChildNodes.Count, "#C5"); }
public void ExportPolicy_CustomEncoding_Soap12August2004() { ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement(); IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension; PolicyConversionContext conversion_context = new CustomPolicyConversionContext(); conversion_context.BindingElements.Add(new MyMessageEncodingElement(MessageVersion.Soap12WSAddressingAugust2004)); export_extension.ExportPolicy(new WsdlExporter(), conversion_context); PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions(); BindingElementCollection binding_elements = conversion_context.BindingElements; Assert.AreEqual(1, binding_assertions.Count, "#A0"); Assert.AreEqual(1, binding_elements.Count, "#A1"); // UsingAddressing XmlNode using_addressing_node = FindAssertionByLocalName(binding_assertions, "UsingAddressing"); Assert.AreEqual(true, using_addressing_node != null, "#B0"); Assert.AreEqual("UsingAddressing", using_addressing_node.LocalName, "#B1"); Assert.AreEqual("http://schemas.xmlsoap.org/ws/2004/08/addressing/policy", using_addressing_node.NamespaceURI, "#B2"); Assert.AreEqual(String.Empty, using_addressing_node.InnerText, "#B3"); Assert.AreEqual(0, using_addressing_node.Attributes.Count, "#B4"); Assert.AreEqual(0, using_addressing_node.ChildNodes.Count, "#B5"); }
public void ExportPolicyDefault() { ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement(); IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension; PolicyConversionContext conversion_context = new CustomPolicyConversionContext(); export_extension.ExportPolicy(new WsdlExporter(), conversion_context); PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions(); BindingElementCollection binding_elements = conversion_context.BindingElements; Assert.AreEqual(2, binding_assertions.Count, "#A0"); Assert.AreEqual(0, binding_elements.Count, "#A1"); // wsaw:UsingAddressing XmlNode using_addressing_node = FindAssertion(binding_assertions, "wsaw:UsingAddressing"); Assert.AreEqual(true, using_addressing_node != null, "#B0"); Assert.AreEqual("UsingAddressing", using_addressing_node.LocalName, "#B1"); Assert.AreEqual("http://www.w3.org/2006/05/addressing/wsdl", using_addressing_node.NamespaceURI, "#B2"); Assert.AreEqual(String.Empty, using_addressing_node.InnerText, "#B3"); Assert.AreEqual(0, using_addressing_node.Attributes.Count, "#B4"); Assert.AreEqual(0, using_addressing_node.ChildNodes.Count, "#B5"); // msb:BinaryEncoding XmlNode binary_encoding_node = FindAssertion(binding_assertions, "msb:BinaryEncoding"); Assert.AreEqual(true, binary_encoding_node != null, "#C0"); Assert.AreEqual("BinaryEncoding", binary_encoding_node.LocalName, "#C1"); Assert.AreEqual("http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1", binary_encoding_node.NamespaceURI, "#C2"); Assert.AreEqual(String.Empty, binary_encoding_node.InnerText, "#C3"); Assert.AreEqual(0, binary_encoding_node.Attributes.Count, "#C4"); Assert.AreEqual(0, binary_encoding_node.ChildNodes.Count, "#C5"); }
public CommandResult Execute(Command command) { try { using (ChannelFactory<IIncinerateService> clientFactory = new ChannelFactory<IIncinerateService>()) { NamedPipeTransportBindingElement transport = new NamedPipeTransportBindingElement(); CustomBinding binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), transport); clientFactory.Endpoint.Binding = binding; clientFactory.Endpoint.Address = new EndpointAddress("net.pipe://IncinerateService/incinerate"); IIncinerateService incinerateProxy = clientFactory.CreateChannel(); CommandResult result = command.Execute(incinerateProxy); clientFactory.Close(); return result; } } catch (FormatException ex) { Console.WriteLine("Illegal agruments"); } catch (CommunicationObjectFaultedException ex) { throw new ServiceException("Service is not working", ex); } catch (EndpointNotFoundException ex) { throw new ServiceException("Service is not running", ex); } catch (CommunicationException ex) { throw new ServiceException("Can not connect to service", ex); } return null; }
public override void ApplyConfiguration(BindingElement bindingElement) { base.ApplyConfiguration(bindingElement); NamedPipeTransportBindingElement element = (NamedPipeTransportBindingElement)bindingElement; this.ConnectionPoolSettings.ApplyConfiguration(element.ConnectionPoolSettings); }
protected internal override void InitializeFrom(BindingElement bindingElement) { base.InitializeFrom(bindingElement); #pragma warning suppress 56506 // Microsoft, base.CopyFrom() validates the argument NamedPipeTransportBindingElement binding = (NamedPipeTransportBindingElement)bindingElement; this.ConnectionPoolSettings.InitializeFrom(binding.ConnectionPoolSettings); this.PipeSettings.InitializeFrom(binding.PipeSettings); }
static CustomBinding CreateNamedPipeBinding() { CustomBinding binding = new CustomBinding(MetadataStrings.MetadataExchangeStrings.NamedPipeBindingName, MetadataStrings.MetadataExchangeStrings.BindingNamespace); NamedPipeTransportBindingElement pipeTransport = new NamedPipeTransportBindingElement(); binding.Elements.Add(pipeTransport); return(binding); }
private static CustomBinding CreateNamedPipeBinding() { CustomBinding binding = new CustomBinding("MetadataExchangeNamedPipeBinding", "http://schemas.microsoft.com/ws/2005/02/mex/bindings", new BindingElement[0]); NamedPipeTransportBindingElement item = new NamedPipeTransportBindingElement(); binding.Elements.Add(item); return(binding); }
public override void ApplyConfiguration(BindingElement bindingElement) { base.ApplyConfiguration(bindingElement); NamedPipeTransportBindingElement binding = (NamedPipeTransportBindingElement)bindingElement; #pragma warning suppress 56506 //Microsoft; base.ApplyConfiguration above checks for bindingElement being null this.ConnectionPoolSettings.ApplyConfiguration(binding.ConnectionPoolSettings); this.PipeSettings.ApplyConfiguration(binding.PipeSettings); }
protected void AddNamedPipeBindingElement(BindingElementCollection bindingElements) { NamedPipeTransportBindingElement item = new NamedPipeTransportBindingElement { MaxPendingConnections = 50 }; item.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 0x19; item.MaxPendingAccepts = 0x19; bindingElements.Add(item); }
static CustomBinding CreateNamedPipeBinding() { #if DESKTOP CustomBinding binding = new CustomBinding(MetadataStrings.MetadataExchangeStrings.NamedPipeBindingName, MetadataStrings.MetadataExchangeStrings.BindingNamespace); NamedPipeTransportBindingElement pipeTransport = new NamedPipeTransportBindingElement(); binding.Elements.Add(pipeTransport); return(binding); #else throw new PlatformNotSupportedException(); #endif }
public NamedPipeChannelFactory(NamedPipeTransportBindingElement bindingElement, BindingContext context) : base(bindingElement, context, GetConnectionGroupName(bindingElement), bindingElement.ConnectionPoolSettings.IdleTimeout, bindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint, false) { if (bindingElement.PipeSettings != null) { this.PipeSettings = bindingElement.PipeSettings.Clone(); } }
public AclSecuredNamedPipeBinding() : base() { NetNamedPipeBinding standardBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.Transport); foreach (BindingElement element in standardBinding.CreateBindingElements()) { NamedPipeTransportBindingElement transportElement = element as NamedPipeTransportBindingElement; base.Elements.Add(null != transportElement ? new AclSecuredNamedPipeTransportBindingElement(transportElement) : element); } AddUserOrGroup(WindowsIdentity.GetCurrent().User); }
private void InitializeFrom(NamedPipeTransportBindingElement namedPipe, BinaryMessageEncodingBindingElement encoding, TransactionFlowBindingElement context) { this.Initialize(); this.HostNameComparisonMode = namedPipe.HostNameComparisonMode; this.MaxBufferPoolSize = namedPipe.MaxBufferPoolSize; this.MaxBufferSize = namedPipe.MaxBufferSize; this.MaxConnections = namedPipe.MaxPendingConnections; this.MaxReceivedMessageSize = namedPipe.MaxReceivedMessageSize; this.TransferMode = namedPipe.TransferMode; this.ReaderQuotas = encoding.ReaderQuotas; this.TransactionFlow = context.Transactions; this.TransactionProtocol = context.TransactionProtocol; }
static Binding CreateRegisterBinding(TransportType transportType) { NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); binding.MaxReceivedMessageSize = ListenerConstants.RegistrationMaxReceivedMessageSize; CustomBinding customBinding = new CustomBinding(binding); NamedPipeTransportBindingElement namedPipeBindingElement = customBinding.Elements.Find <NamedPipeTransportBindingElement>(); namedPipeBindingElement.ExposeConnectionProperty = true; namedPipeBindingElement.AllowedUsers = ListenerConfig.GetAllowAccounts(transportType); customBinding.ReceiveTimeout = TimeSpan.MaxValue; return(customBinding); }
public void ExportPolicy_CustomEncoding_Soap12() { ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement(); IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension; PolicyConversionContext conversion_context = new CustomPolicyConversionContext(); conversion_context.BindingElements.Add(new MyMessageEncodingElement(MessageVersion.Soap12)); export_extension.ExportPolicy(new WsdlExporter(), conversion_context); PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions(); BindingElementCollection binding_elements = conversion_context.BindingElements; Assert.AreEqual(0, binding_assertions.Count, "#A0"); Assert.AreEqual(1, binding_elements.Count, "#A1"); }
// check that properties of the HttpTransportBindingElement and // MessageEncodingBindingElement not exposed as properties on BasicHttpBinding // match default values of the binding elements bool IsBindingElementsMatch(NamedPipeTransportBindingElement namedPipe, BinaryMessageEncodingBindingElement encoding, TransactionFlowBindingElement context) { if (!this.namedPipe.IsMatch(namedPipe)) { return(false); } if (!this.encoding.IsMatch(encoding)) { return(false); } if (!this.context.IsMatch(context)) { return(false); } return(true); }
void Initialize() { this.httpTransport = new HttpTransportBindingElement(); this.tcpTransport = new TcpTransportBindingElement(); this.namedPipeTransport = new NamedPipeTransportBindingElement(); this.textEncoding = new TextMessageEncodingBindingElement(); this.mtomEncoding = new MtomMessageEncodingBindingElement(); this.binaryEncoding = new BinaryMessageEncodingBindingElement(); this.httpTransport.ManualAddressing = true; this.tcpTransport.ManualAddressing = true; this.namedPipeTransport.ManualAddressing = true; this.transport = RouterTransport.Http; this.messageEncoding = MessageEncoding.Text; }
public void DefaultValues () { NamedPipeTransportBindingElement be = new NamedPipeTransportBindingElement (); Assert.AreEqual (TimeSpan.FromSeconds (5), be.ChannelInitializationTimeout, "#1"); Assert.AreEqual (0x2000, be.ConnectionBufferSize, "#2"); Assert.AreEqual (HostNameComparisonMode.StrongWildcard, be.HostNameComparisonMode, "#3"); Assert.AreEqual (0x10000, be.MaxBufferSize, "#4"); Assert.AreEqual (TimeSpan.FromMilliseconds (200), be.MaxOutputDelay, "#5"); Assert.AreEqual (1, be.MaxPendingAccepts, "#6"); Assert.AreEqual (10, be.MaxPendingConnections, "#7"); Assert.AreEqual (TransferMode.Buffered, be.TransferMode, "#8"); Assert.AreEqual ("net.pipe", be.Scheme, "#11"); NamedPipeConnectionPoolSettings pool = be.ConnectionPoolSettings; Assert.IsNotNull (pool, "#13"); Assert.AreEqual ("default", pool.GroupName, "#14"); Assert.AreEqual (TimeSpan.FromSeconds (120), pool.IdleTimeout, "#15"); Assert.AreEqual (10, pool.MaxOutboundConnectionsPerEndpoint, "#17"); }
public void AddAllMexEndPoints() { Debug.Assert(HasMexEndpoint == false); foreach (Uri baseAddress in BaseAddresses) { BindingElement bindingElement = null; switch (baseAddress.Scheme) { case "net.tcp": { bindingElement = new TcpTransportBindingElement(); break; } case "net.pipe": { bindingElement = new NamedPipeTransportBindingElement(); break; } case "http": { bindingElement = new HttpTransportBindingElement(); break; } case "https": { bindingElement = new HttpsTransportBindingElement(); break; } } if (bindingElement != null) { Binding binding = new CustomBinding(bindingElement); AddServiceEndpoint(typeof(IMetadataExchange), binding, "MEX"); } } }
/// <summary> /// Gets the endpoints. /// </summary> /// <param name="mexAddress">The mex address.</param> /// <returns>ServiceEndpoint[][].</returns> public static ServiceEndpoint[] GetEndpoints(string mexAddress) { if (String.IsNullOrEmpty(mexAddress)) { Debug.Assert(false, "Empty address"); return(null); } var address = new Uri(mexAddress); ServiceEndpointCollection endpoints = null; if (address.Scheme == Uri.UriSchemeHttp) { var be = new HttpTransportBindingElement { MaxReceivedMessageSize = BindingHelper.BindingConst.MaxReceivedMessageSize }; endpoints = GetEndpointsViaHttpMex(mexAddress, be); } else if (address.Scheme == Uri.UriSchemeHttps) { var be = new HttpsTransportBindingElement { MaxReceivedMessageSize = BindingHelper.BindingConst.MaxReceivedMessageSize }; endpoints = GetEndpointsViaHttpMex(mexAddress, be); } else if (address.Scheme == Uri.UriSchemeNetTcp) { var be = new TcpTransportBindingElement { MaxReceivedMessageSize = BindingHelper.BindingConst.MaxReceivedMessageSize }; endpoints = QueryMexEndpoint(mexAddress, be); } else if (address.Scheme == Uri.UriSchemeNetPipe) { var be = new NamedPipeTransportBindingElement { MaxReceivedMessageSize = BindingHelper.BindingConst.MaxReceivedMessageSize }; endpoints = QueryMexEndpoint(mexAddress, be); } return(endpoints.ToArray()); }
static void Main() { // protected // NamedPipeTransportBindingElement bElementClone = // new NamedPipeTransportBindingElement(bElement); // <Snippet3> // <Snippet2> // <Snippet0> // <Snippet1> NamedPipeTransportBindingElement bElement = new NamedPipeTransportBindingElement(); // </Snippet1> NamedPipeConnectionPoolSettings connectionPoolSettings = bElement.ConnectionPoolSettings; // </Snippet0> // </Snippet2> // </Snippet3> // <Snippet4> string scheme = bElement.Scheme; // </Snippet4> // <Snippet5> BindingElement bElementCopy = bElement.Clone(); // </Snippet5> // <Snippet8> BasicHttpBinding binding = new BasicHttpBinding(); ISecurityCapabilities b = binding.GetProperty <ISecurityCapabilities> (new BindingParameterCollection()); bool SupportsServerAuthentication = b.SupportsServerAuthentication; // </Snippet8> }
public void DefaultValues() { NamedPipeTransportBindingElement be = new NamedPipeTransportBindingElement(); Assert.AreEqual(TimeSpan.FromSeconds(5), be.ChannelInitializationTimeout, "#1"); Assert.AreEqual(0x2000, be.ConnectionBufferSize, "#2"); Assert.AreEqual(HostNameComparisonMode.StrongWildcard, be.HostNameComparisonMode, "#3"); Assert.AreEqual(0x10000, be.MaxBufferSize, "#4"); Assert.AreEqual(TimeSpan.FromMilliseconds(200), be.MaxOutputDelay, "#5"); Assert.AreEqual(1, be.MaxPendingAccepts, "#6"); Assert.AreEqual(10, be.MaxPendingConnections, "#7"); Assert.AreEqual(TransferMode.Buffered, be.TransferMode, "#8"); Assert.AreEqual("net.pipe", be.Scheme, "#11"); NamedPipeConnectionPoolSettings pool = be.ConnectionPoolSettings; Assert.IsNotNull(pool, "#13"); Assert.AreEqual("default", pool.GroupName, "#14"); Assert.AreEqual(TimeSpan.FromSeconds(120), pool.IdleTimeout, "#15"); Assert.AreEqual(10, pool.MaxOutboundConnectionsPerEndpoint, "#17"); }
static void Main(string[] args) { try { //建立自定义通道栈 BindingElement[] bindingElements = new BindingElement[3]; bindingElements[0] = new TextMessageEncodingBindingElement();//文本编码 //OneWayBindingElement 可以使得传输通道支持数据报模式 bindingElements[1] = new OneWayBindingElement(); //http传输 // bindingElements[2] = new HttpTransportBindingElement(); //命名管道传输 bindingElements[2] = new NamedPipeTransportBindingElement(); CustomBinding binding = new CustomBinding(bindingElements); using (Message message = Message.CreateMessage(binding.MessageVersion, "sendMessage", "Message Body")) //创建消息 { //创建ChannelFactory IChannelFactory <IOutputChannel> factory = binding.BuildChannelFactory <IOutputChannel>(new BindingParameterCollection()); factory.Open();//打开ChannelFactory //创建IoutputChannel IOutputChannel outputChannel = factory.CreateChannel(new System.ServiceModel.EndpointAddress("net.pipe://localhost/InputService")); outputChannel.Open(); //打开通道 outputChannel.Send(message); //发送消息 Console.WriteLine("已经成功发送消息!"); outputChannel.Close(); //关闭通道 factory.Close(); //关闭工厂 } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { Console.Read(); } }
public void CanBuildChannelFactory () { NamedPipeTransportBindingElement be = new NamedPipeTransportBindingElement (); BindingContext ctx = new BindingContext ( new CustomBinding (), empty_params); Assert.IsFalse (be.CanBuildChannelFactory<IRequestChannel> (ctx), "#1"); Assert.IsFalse (be.CanBuildChannelFactory<IInputChannel> (ctx), "#2"); Assert.IsFalse (be.CanBuildChannelFactory<IReplyChannel> (ctx), "#3"); Assert.IsFalse (be.CanBuildChannelFactory<IOutputChannel> (ctx), "#4"); Assert.IsFalse (be.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#5"); Assert.IsFalse (be.CanBuildChannelFactory<IInputSessionChannel> (ctx), "#6"); Assert.IsFalse (be.CanBuildChannelFactory<IReplySessionChannel> (ctx), "#7"); Assert.IsFalse (be.CanBuildChannelFactory<IOutputSessionChannel> (ctx), "#8"); // IServiceChannel is not supported Assert.IsFalse (be.CanBuildChannelFactory<IServiceChannel> (ctx), "#9"); Assert.IsFalse (be.CanBuildChannelFactory<IClientChannel> (ctx), "#10"); Assert.IsTrue (be.CanBuildChannelFactory<IDuplexSessionChannel> (ctx), "#11"); Assert.IsTrue (be.CanBuildChannelFactory<IDuplexSessionChannel> (ctx), "#12"); }
private static Binding DefaultBuildBinding() { var messageEncodingElement = new BinaryMessageEncodingBindingElement(); #if !SILVERLIGHT messageEncodingElement.ReaderQuotas.MaxArrayLength = MaxMessageLength; messageEncodingElement.ReaderQuotas.MaxStringContentLength = MaxMessageLength; #endif #if USENAMEDPIPES && !SILVERLIGHT NamedPipeTransportBindingElement transportElement = new NamedPipeTransportBindingElement(); #else TcpTransportBindingElement transportElement = new TcpTransportBindingElement(); #endif transportElement.MaxBufferSize = MaxMessageLength; transportElement.MaxReceivedMessageSize = MaxMessageLength; var binding = new CustomBinding(messageEncodingElement, transportElement); binding.SendTimeout = TimeSpan.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; return(binding); }
public void ExportPolicy() { ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement(); binding_element.ChannelInitializationTimeout = TimeSpan.FromSeconds(3); binding_element.ConnectionBufferSize = binding_element.ConnectionBufferSize / 2; binding_element.HostNameComparisonMode = HostNameComparisonMode.WeakWildcard; binding_element.ManualAddressing = !binding_element.ManualAddressing; binding_element.MaxBufferSize = binding_element.MaxBufferSize / 2; binding_element.MaxBufferPoolSize = binding_element.MaxBufferPoolSize / 2; binding_element.MaxOutputDelay = TimeSpan.FromSeconds(3); binding_element.MaxPendingAccepts = 3; binding_element.MaxPendingConnections = 15; binding_element.MaxReceivedMessageSize = binding_element.MaxReceivedMessageSize / 2; binding_element.TransferMode = TransferMode.Streamed; // Causes an assertion with Streamed* values IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension; PolicyConversionContext conversion_context = new CustomPolicyConversionContext(); export_extension.ExportPolicy(new WsdlExporter(), conversion_context); PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions(); BindingElementCollection binding_elements = conversion_context.BindingElements; Assert.AreEqual(3, binding_assertions.Count, "#A0"); Assert.AreEqual(0, binding_elements.Count, "#A1"); // msf:Streamed XmlNode streamed_node = FindAssertion(binding_assertions, "msf:Streamed"); Assert.AreEqual(true, streamed_node != null, "#B0"); Assert.AreEqual("Streamed", streamed_node.LocalName, "#B1"); Assert.AreEqual("http://schemas.microsoft.com/ws/2006/05/framing/policy", streamed_node.NamespaceURI, "#B2"); Assert.AreEqual(String.Empty, streamed_node.InnerText, "#B3"); Assert.AreEqual(0, streamed_node.Attributes.Count, "#B4"); Assert.AreEqual(0, streamed_node.ChildNodes.Count, "#B5"); }
public static ServiceEndpointCollection GetEndpoints(string mexAddress) { Uri mexUri = new Uri(mexAddress); TransportBindingElement transportElement; switch (mexUri.Scheme) { case "net.tcp": transportElement = new TcpTransportBindingElement(); break; case "net.pipe": transportElement = new NamedPipeTransportBindingElement(); break; case "http": transportElement = new HttpTransportBindingElement(); break; case "https": transportElement = new HttpsTransportBindingElement(); break; default: throw new NotSupportedException("Scheme not supported."); } transportElement.MaxReceivedMessageSize *= MessageSizeMultiplier; return GetEndpoints(mexUri, transportElement); ; }
public void CanBuildChannelListener() { NamedPipeTransportBindingElement be = new NamedPipeTransportBindingElement(); BindingContext ctx = new BindingContext( new CustomBinding(), empty_params); Assert.IsFalse(be.CanBuildChannelListener <IReplyChannel> (ctx), "#1"); Assert.IsFalse(be.CanBuildChannelListener <IOutputChannel> (ctx), "#2"); Assert.IsFalse(be.CanBuildChannelListener <IRequestChannel> (ctx), "#3"); Assert.IsFalse(be.CanBuildChannelListener <IInputChannel> (ctx), "#4"); Assert.IsFalse(be.CanBuildChannelListener <IReplySessionChannel> (ctx), "#5"); Assert.IsFalse(be.CanBuildChannelListener <IOutputSessionChannel> (ctx), "#6"); Assert.IsFalse(be.CanBuildChannelListener <IRequestSessionChannel> (ctx), "#7"); Assert.IsFalse(be.CanBuildChannelListener <IInputSessionChannel> (ctx), "#8"); // IServiceChannel is not supported Assert.IsFalse(be.CanBuildChannelListener <IServiceChannel> (ctx), "#9"); Assert.IsFalse(be.CanBuildChannelListener <IClientChannel> (ctx), "#10"); Assert.IsFalse(be.CanBuildChannelListener <IDuplexChannel> (ctx), "#11"); Assert.IsTrue(be.CanBuildChannelListener <IDuplexSessionChannel> (ctx), "#12"); }
void Explore(string mexAddress) { ServiceNode existingNode = null; try { Uri address = new Uri(mexAddress); ServiceEndpointCollection endpoints = null; //Find if tree already contain this address foreach(ServiceNode node in m_MexTree.Nodes) { if(node.MexAddress == mexAddress) { if(node.Text == "Unspecified Base Address" || node.Text == "Invalid Address") { node.ImageIndex = node.SelectedImageIndex = ServiceIndex; } existingNode = node; break; } } if(address.Scheme == "http") { HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.MaxReceivedMessageSize *= MessageMultiplier; //Try the HTTP MEX Endpoint try { endpoints = GetEndpoints(httpBindingElement); } catch {} //Try over HTTP-GET if(endpoints == null) { string httpGetAddress = mexAddress; if(mexAddress.EndsWith("?wsdl") == false) { httpGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpBindingElement); MetadataExchangeClient MEXClient = new MetadataExchangeClient(binding); MetadataSet metadata = MEXClient.GetMetadata(new Uri(httpGetAddress),MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if(address.Scheme == "https") { HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); httpsBindingElement.MaxReceivedMessageSize *= MessageMultiplier; //Try the HTTPS MEX Endpoint try { endpoints = GetEndpoints(httpsBindingElement); } catch { } //Try over HTTP-GET if(endpoints == null) { string httpsGetAddress = mexAddress; if(mexAddress.EndsWith("?wsdl") == false) { httpsGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpsBindingElement); MetadataExchangeClient MEXClient = new MetadataExchangeClient(binding); MetadataSet metadata = MEXClient.GetMetadata(new Uri(httpsGetAddress),MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if(address.Scheme == "net.tcp") { TcpTransportBindingElement tcpBindingElement = new TcpTransportBindingElement(); tcpBindingElement.MaxReceivedMessageSize *= MessageMultiplier; endpoints = GetEndpoints(tcpBindingElement); } if(address.Scheme == "net.pipe") { NamedPipeTransportBindingElement ipcBindingElement = new NamedPipeTransportBindingElement(); ipcBindingElement.MaxReceivedMessageSize *= MessageMultiplier; endpoints = GetEndpoints(ipcBindingElement); } ProcessMetaData(existingNode,mexAddress,endpoints); } catch { if(existingNode == null) { CurrentNode = new ServiceNode(mexAddress,this,"Invalid Address",ServiceError,ServiceError); m_MexTree.Nodes.Add(CurrentNode); } else { CurrentNode.Text = "Invalid Address"; CurrentNode.Nodes.Clear(); CurrentNode.ImageIndex = CurrentNode.SelectedImageIndex = ServiceError; } } }
void Explore(string mexAddress) { ServiceNode existingNode = null; try { Uri address = new Uri(mexAddress); ServiceEndpointCollection endpoints = null; //Find if tree already contain this address foreach (ServiceNode node in m_MexTree.Nodes) { if (node.MexAddress == mexAddress) { if (node.Text == "Unspecified Base Address" || node.Text == "Invalid Address") { node.ImageIndex = node.SelectedImageIndex = ServiceIndex; } existingNode = node; break; } } if (address.Scheme == "http") { HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.MaxReceivedMessageSize *= MessageMultiplier; //Try the HTTP MEX Endpoint try { endpoints = GetEndpoints(httpBindingElement); } catch {} //Try over HTTP-GET if (endpoints == null) { string httpGetAddress = mexAddress; if (mexAddress.EndsWith("?wsdl") == false) { httpGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpBindingElement); MetadataExchangeClient MEXClient = new MetadataExchangeClient(binding); MetadataSet metadata = MEXClient.GetMetadata(new Uri(httpGetAddress), MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if (address.Scheme == "https") { HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); httpsBindingElement.MaxReceivedMessageSize *= MessageMultiplier; //Try the HTTPS MEX Endpoint try { endpoints = GetEndpoints(httpsBindingElement); } catch { } //Try over HTTP-GET if (endpoints == null) { string httpsGetAddress = mexAddress; if (mexAddress.EndsWith("?wsdl") == false) { httpsGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpsBindingElement); MetadataExchangeClient MEXClient = new MetadataExchangeClient(binding); MetadataSet metadata = MEXClient.GetMetadata(new Uri(httpsGetAddress), MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if (address.Scheme == "net.tcp") { TcpTransportBindingElement tcpBindingElement = new TcpTransportBindingElement(); tcpBindingElement.MaxReceivedMessageSize *= MessageMultiplier; endpoints = GetEndpoints(tcpBindingElement); } if (address.Scheme == "net.pipe") { NamedPipeTransportBindingElement ipcBindingElement = new NamedPipeTransportBindingElement(); ipcBindingElement.MaxReceivedMessageSize *= MessageMultiplier; endpoints = GetEndpoints(ipcBindingElement); } ProcessMetaData(existingNode, mexAddress, endpoints); } catch { if (existingNode == null) { CurrentNode = new ServiceNode(mexAddress, this, "Invalid Address", ServiceError, ServiceError); m_MexTree.Nodes.Add(CurrentNode); } else { CurrentNode.Text = "Invalid Address"; CurrentNode.Nodes.Clear(); CurrentNode.ImageIndex = CurrentNode.SelectedImageIndex = ServiceError; } } }
internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { binding = null; if (elements.Count > 4) { return(false); } TransactionFlowBindingElement context = null; BinaryMessageEncodingBindingElement encoding = null; WindowsStreamSecurityBindingElement security = null; NamedPipeTransportBindingElement namedPipe = null; foreach (BindingElement element in elements) { if (element is TransactionFlowBindingElement) { context = element as TransactionFlowBindingElement; } else if (element is BinaryMessageEncodingBindingElement) { encoding = element as BinaryMessageEncodingBindingElement; } else if (element is WindowsStreamSecurityBindingElement) { security = element as WindowsStreamSecurityBindingElement; } else if (element is NamedPipeTransportBindingElement) { namedPipe = element as NamedPipeTransportBindingElement; } else { return(false); } } if (namedPipe == null) { return(false); } if (encoding == null) { return(false); } if (context == null) { context = GetDefaultTransactionFlowBindingElement(); } NetNamedPipeSecurity pipeSecurity; if (!TryCreateSecurity(security, out pipeSecurity)) { return(false); } NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding(pipeSecurity); netNamedPipeBinding.InitializeFrom(namedPipe, encoding, context); if (!netNamedPipeBinding.IsBindingElementsMatch(namedPipe, encoding, context)) { return(false); } binding = netNamedPipeBinding; return(true); }
internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { binding = null; if (elements.Count > 4) return false; TransactionFlowBindingElement context = null; BinaryMessageEncodingBindingElement encoding = null; WindowsStreamSecurityBindingElement security = null; NamedPipeTransportBindingElement namedPipe = null; foreach (BindingElement element in elements) { if (element is TransactionFlowBindingElement) context = element as TransactionFlowBindingElement; else if (element is BinaryMessageEncodingBindingElement) encoding = element as BinaryMessageEncodingBindingElement; else if (element is WindowsStreamSecurityBindingElement) security = element as WindowsStreamSecurityBindingElement; else if (element is NamedPipeTransportBindingElement) namedPipe = element as NamedPipeTransportBindingElement; else return false; } if (namedPipe == null) return false; if (encoding == null) return false; if (context == null) context = GetDefaultTransactionFlowBindingElement(); NetNamedPipeSecurity pipeSecurity; if (!TryCreateSecurity(security, out pipeSecurity)) return false; NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding(pipeSecurity); netNamedPipeBinding.InitializeFrom(namedPipe, encoding, context); if (!netNamedPipeBinding.IsBindingElementsMatch(namedPipe, encoding, context)) return false; binding = netNamedPipeBinding; return true; }
static TransportBindingElement CreateTransportBindingElements(string transportUri, PolicyConversionContext policyContext) { TransportBindingElement transportBindingElement = null; // Try and Create TransportBindingElement switch (transportUri) { case TransportPolicyConstants.HttpTransportUri: transportBindingElement = GetHttpTransportBindingElement(policyContext); break; case TransportPolicyConstants.TcpTransportUri: transportBindingElement = new TcpTransportBindingElement(); break; case TransportPolicyConstants.NamedPipeTransportUri: transportBindingElement = new NamedPipeTransportBindingElement(); break; case TransportPolicyConstants.MsmqTransportUri: transportBindingElement = new MsmqTransportBindingElement(); break; case TransportPolicyConstants.PeerTransportUri: #pragma warning disable 0618 transportBindingElement = new PeerTransportBindingElement(); #pragma warning restore 0618 break; case TransportPolicyConstants.WebSocketTransportUri: HttpTransportBindingElement httpTransport = GetHttpTransportBindingElement(policyContext); httpTransport.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always; httpTransport.WebSocketSettings.SubProtocol = WebSocketTransportSettings.SoapSubProtocol; transportBindingElement = httpTransport; break; default: // There may be another registered converter that can handle this transport. break; } return transportBindingElement; }
private void CreateControlProxy() { EndpointAddress remoteAddress = new EndpointAddress(System.ServiceModel.Activation.Utility.FormatListenerEndpoint(this.serviceName, this.listenerEndPoint), new AddressHeader[0]); NamedPipeTransportBindingElement element = new NamedPipeTransportBindingElement(); CustomBinding binding = new CustomBinding(new BindingElement[] { element }); InstanceContext callbackInstance = new InstanceContext(null, this, false); ChannelFactory<IConnectionRegister> factory = new DuplexChannelFactory<IConnectionRegister>(callbackInstance, binding, remoteAddress); factory.Endpoint.Behaviors.Add(new SharedListenerProxyBehavior(this)); IConnectionRegister register = factory.CreateChannel(); this.channelFactory = factory; this.controlSessionWithListener = register as IDuplexContextChannel; }
private void Initialize() { this.namedPipe = new NamedPipeTransportBindingElement(); this.encoding = new BinaryMessageEncodingBindingElement(); this.context = GetDefaultTransactionFlowBindingElement(); }
internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { NetNamedPipeSecurity security; binding = null; if (elements.Count > 4) { return false; } TransactionFlowBindingElement context = null; BinaryMessageEncodingBindingElement encoding = null; WindowsStreamSecurityBindingElement wssbe = null; NamedPipeTransportBindingElement namedPipe = null; foreach (BindingElement element5 in elements) { if (element5 is TransactionFlowBindingElement) { context = element5 as TransactionFlowBindingElement; } else if (element5 is BinaryMessageEncodingBindingElement) { encoding = element5 as BinaryMessageEncodingBindingElement; } else if (element5 is WindowsStreamSecurityBindingElement) { wssbe = element5 as WindowsStreamSecurityBindingElement; } else if (element5 is NamedPipeTransportBindingElement) { namedPipe = element5 as NamedPipeTransportBindingElement; } else { return false; } } if (namedPipe == null) { return false; } if (encoding == null) { return false; } if (context == null) { context = GetDefaultTransactionFlowBindingElement(); } if (!TryCreateSecurity(wssbe, out security)) { return false; } NetNamedPipeBinding binding2 = new NetNamedPipeBinding(security); binding2.InitializeFrom(namedPipe, encoding, context); if (!binding2.IsBindingElementsMatch(namedPipe, encoding, context)) { return false; } binding = binding2; return true; }
static void Main(string[] args) { CommandLineArgs cmdArgs = new CommandLineArgs(args); try { using (ChannelFactory<IIncinerateService> clientFactory = new ChannelFactory<IIncinerateService>()) { NamedPipeTransportBindingElement transport = new NamedPipeTransportBindingElement(); CustomBinding binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), transport); clientFactory.Endpoint.Binding = binding; clientFactory.Endpoint.Address = new EndpointAddress("net.pipe://IncinerateService/incinerate"); IIncinerateService customersProxy = clientFactory.CreateChannel(); if (cmdArgs.GetAgents) { IList<AgentInfo> lines = customersProxy.GetAgents(); StringBuilder sb = new StringBuilder(); foreach (AgentInfo line in lines) { sb.AppendLine(line.Name + ": " + line.Status); } Console.WriteLine(sb.ToString()); } else if (cmdArgs.ProcessIDs != null && cmdArgs.AgentName != null) { string[] splitted = cmdArgs.ProcessIDs.Split(','); IList<int> pids = new List<int>(); foreach (string pidStr in splitted) { pids.Add(Int32.Parse(pidStr)); } customersProxy.AddLearningAgent(pids, cmdArgs.AgentName); } else if (cmdArgs.Watched != null && cmdArgs.StrategyRed != null && cmdArgs.StrategyYellow != null && cmdArgs.P1 != null && cmdArgs.P2 != null) { customersProxy.Watch(cmdArgs.Watched, cmdArgs.StrategyRed, cmdArgs.StrategyYellow, Double.Parse(cmdArgs.P1), Double.Parse(cmdArgs.P2)); } else if (cmdArgs.Stop != null) { customersProxy.Stop(); } else { cmdArgs.PrintUsage(); } clientFactory.Close(); } } catch (CommunicationObjectFaultedException ex) { Console.WriteLine("Service is not working"); } catch (FormatException ex) { Console.WriteLine("Illegal agruments"); } catch (EndpointNotFoundException ex) { Console.WriteLine("Service is not running"); } catch (CommunicationException ex) { Console.WriteLine("Can not connect to service"); } }
public static ServiceEndpoint[] GetEndpoints(string mexAddress) { if(string.IsNullOrWhiteSpace(mexAddress)) { throw new ArgumentException("mexAddress"); } Uri address = new Uri(mexAddress); ServiceEndpointCollection endpoints = null; BindingElement bindingElement = null; //Try over HTTP-GET first if(address.Scheme == Uri.UriSchemeHttp || address.Scheme == Uri.UriSchemeHttps) { string getAddress = mexAddress; if(mexAddress.EndsWith("?wsdl") == false) { getAddress += "?wsdl"; } if(address.Scheme == Uri.UriSchemeHttp) { HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; bindingElement = httpBindingElement; } else { HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); httpsBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; bindingElement = httpsBindingElement; } CustomBinding binding = new CustomBinding(bindingElement); MetadataExchangeClient mexClient = new MetadataExchangeClient(binding); MetadataSet metadata = mexClient.GetMetadata(new Uri(getAddress),MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); return endpoints.ToArray(); } //Try MEX endpoint: if(address.Scheme == Uri.UriSchemeHttp) { bindingElement = new HttpTransportBindingElement(); } if(address.Scheme == Uri.UriSchemeHttps) { bindingElement = new HttpsTransportBindingElement(); } if(address.Scheme == Uri.UriSchemeNetTcp) { bindingElement = new TcpTransportBindingElement(); } if(address.Scheme == Uri.UriSchemeNetPipe) { bindingElement = new NamedPipeTransportBindingElement(); } endpoints = QueryMexEndpoint(mexAddress,bindingElement); return endpoints.ToArray(); }
static CustomBinding CreateNamedPipeBinding() { CustomBinding binding = new CustomBinding(MetadataStrings.MetadataExchangeStrings.NamedPipeBindingName, MetadataStrings.MetadataExchangeStrings.BindingNamespace); NamedPipeTransportBindingElement pipeTransport = new NamedPipeTransportBindingElement(); binding.Elements.Add(pipeTransport); return binding; }
private bool IsBindingElementsMatch(NamedPipeTransportBindingElement namedPipe, BinaryMessageEncodingBindingElement encoding, TransactionFlowBindingElement context) { if (!this.namedPipe.IsMatch(namedPipe)) { return false; } if (!this.encoding.IsMatch(encoding)) { return false; } if (!this.context.IsMatch(context)) { return false; } return true; }
public static ServiceEndpoint[] GetEndpoints(this EndpointAddress endpointAddress) { if (endpointAddress.IsNull() || endpointAddress.Uri == default(Uri)) return null; Uri address = endpointAddress.Uri; // make sure url is end with '?wsdl' //if (address.AbsoluteUri.EndsWith("?wsdl", true, CultureInfo.InvariantCulture) == false) //{ // string wsdlAddress = address.AbsoluteUri + "?wsdl"; // address = new Uri(wsdlAddress); //} address = address.EnsureWsdl(); ServiceEndpointCollection serviceEndpoints = null; BindingElement bindingElement = null; // address is http/https if (address.Scheme == Uri.UriSchemeHttp || address.Scheme == Uri.UriSchemeHttps) { if (address.Scheme == Uri.UriSchemeHttp) { var httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.MaxReceivedMessageSize *= 5; // default set bindingElement = httpBindingElement; } else { var httpsBindingElement = new HttpsTransportBindingElement(); httpsBindingElement.MaxReceivedMessageSize *= 5; // default set bindingElement = httpsBindingElement; } try { CustomBinding binding = new CustomBinding(bindingElement); var mexClient = new MetadataExchangeClient(binding); var metadata = mexClient.GetMetadata(address, MetadataExchangeClientMode.HttpGet); serviceEndpoints = (new WsdlImporter(metadata)).ImportAllEndpoints(); return serviceEndpoints.ToArray(); } catch { // do nothing, try another metadata exchange to get metadata } } if (address.Scheme == Uri.UriSchemeHttp) { bindingElement = new HttpTransportBindingElement(); } if (address.Scheme == Uri.UriSchemeHttps) { bindingElement = new HttpsTransportBindingElement(); } if (address.Scheme == Uri.UriSchemeNetTcp) { bindingElement = new TcpTransportBindingElement(); } if (address.Scheme == Uri.UriSchemeNetPipe) { bindingElement = new NamedPipeTransportBindingElement(); } serviceEndpoints = QueryMexEndpoints(address.AbsoluteUri, bindingElement); return serviceEndpoints.ToArray(); }
void OnExplore(object sender,EventArgs e) { m_ExploreButton.Enabled = false; string mexAddress = m_MexAddressTextBox.Text; if(String.IsNullOrEmpty(mexAddress)) { Debug.Assert(false,"Empty address"); } m_MexTree.Nodes.Clear(); DisplayBlankControl(); SplashScreen splash = new SplashScreen(Resources.Progress); try { Uri address = new Uri(mexAddress); ServiceEndpointCollection endpoints = null; if(address.Scheme == "http") { HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.MaxReceivedMessageSize *= MessageMultiplier; //Try the HTTP MEX Endpoint try { endpoints = GetEndpoints(httpBindingElement); } catch {} //Try over HTTP-GET if(endpoints == null) { string httpGetAddress = mexAddress; if(mexAddress.EndsWith("?wsdl") == false) { httpGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpBindingElement); MetadataExchangeClient MEXClient = new MetadataExchangeClient(binding); MetadataSet metadata = MEXClient.GetMetadata(new Uri(httpGetAddress),MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if(address.Scheme == "https") { HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); httpsBindingElement.MaxReceivedMessageSize *= MessageMultiplier; //Try the HTTPS MEX Endpoint try { endpoints = GetEndpoints(httpsBindingElement); } catch { } //Try over HTTP-GET if(endpoints == null) { string httpsGetAddress = mexAddress; if(mexAddress.EndsWith("?wsdl") == false) { httpsGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpsBindingElement); MetadataExchangeClient MEXClient = new MetadataExchangeClient(binding); MetadataSet metadata = MEXClient.GetMetadata(new Uri(httpsGetAddress),MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if(address.Scheme == "net.tcp") { TcpTransportBindingElement tcpBindingElement = new TcpTransportBindingElement(); tcpBindingElement.MaxReceivedMessageSize *= MessageMultiplier; endpoints = GetEndpoints(tcpBindingElement); } if(address.Scheme == "net.pipe") { NamedPipeTransportBindingElement ipcBindingElement = new NamedPipeTransportBindingElement(); ipcBindingElement.MaxReceivedMessageSize *= MessageMultiplier; endpoints = GetEndpoints(ipcBindingElement); } ProcessMetaData(endpoints); } catch { m_MexTree.Nodes.Clear(); m_Root = new ServiceNode(this,"Invalid Base Address",ServiceError,ServiceError); m_MexTree.Nodes.Add(m_Root); return; } finally { splash.Close(); m_ExploreButton.Enabled = true; } }
public void ExportPolicy_CustomEncoding_Soap12 () { ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement (); IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension; PolicyConversionContext conversion_context = new CustomPolicyConversionContext (); conversion_context.BindingElements.Add (new MyMessageEncodingElement (MessageVersion.Soap12)); export_extension.ExportPolicy (new WsdlExporter (), conversion_context); PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions (); BindingElementCollection binding_elements = conversion_context.BindingElements; Assert.AreEqual (0, binding_assertions.Count, "#A0"); Assert.AreEqual (1, binding_elements.Count, "#A1"); }
public void ExportPolicy_CustomEncoding_Soap12August2004 () { ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement (); IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension; PolicyConversionContext conversion_context = new CustomPolicyConversionContext (); conversion_context.BindingElements.Add (new MyMessageEncodingElement (MessageVersion.Soap12WSAddressingAugust2004)); export_extension.ExportPolicy (new WsdlExporter (), conversion_context); PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions (); BindingElementCollection binding_elements = conversion_context.BindingElements; Assert.AreEqual (1, binding_assertions.Count, "#A0"); Assert.AreEqual (1, binding_elements.Count, "#A1"); // UsingAddressing XmlNode using_addressing_node = FindAssertionByLocalName (binding_assertions, "UsingAddressing"); Assert.AreEqual (true, using_addressing_node != null, "#B0"); Assert.AreEqual ("UsingAddressing", using_addressing_node.LocalName, "#B1"); Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2004/08/addressing/policy", using_addressing_node.NamespaceURI, "#B2"); Assert.AreEqual (String.Empty, using_addressing_node.InnerText, "#B3"); Assert.AreEqual (0, using_addressing_node.Attributes.Count, "#B4"); Assert.AreEqual (0, using_addressing_node.ChildNodes.Count, "#B5"); }
public static ServiceEndpoint[] GetEndpoints(string mexAddress) { if (String.IsNullOrEmpty(mexAddress)) { Debug.Assert(false, "Empty address"); return null; } Uri address = new Uri(mexAddress); ServiceEndpointCollection endpoints = null; if (address.Scheme == "http") { HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; //Try the HTTP MEX Endpoint try { endpoints = QueryMexEndpoint(mexAddress, httpBindingElement); } catch { } //Try over HTTP-GET if (endpoints == null) { string httpGetAddress = mexAddress; if (mexAddress.EndsWith("?wsdl") == false) { httpGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpBindingElement); MetadataExchangeClient mexClient = new MetadataExchangeClient(binding); MetadataSet metadata = mexClient.GetMetadata(new Uri(httpGetAddress), MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if (address.Scheme == "https") { HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); httpsBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; //Try the HTTPS MEX Endpoint try { endpoints = QueryMexEndpoint(mexAddress, httpsBindingElement); } catch { } //Try over HTTPS-GET if (endpoints == null) { string httpsGetAddress = mexAddress; if (mexAddress.EndsWith("?wsdl") == false) { httpsGetAddress += "?wsdl"; } CustomBinding binding = new CustomBinding(httpsBindingElement); MetadataExchangeClient mexClient = new MetadataExchangeClient(binding); MetadataSet metadata = mexClient.GetMetadata(new Uri(httpsGetAddress), MetadataExchangeClientMode.HttpGet); MetadataImporter importer = new WsdlImporter(metadata); endpoints = importer.ImportAllEndpoints(); } } if (address.Scheme == "net.tcp") { TcpTransportBindingElement tcpBindingElement = new TcpTransportBindingElement(); tcpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; endpoints = QueryMexEndpoint(mexAddress, tcpBindingElement); } if (address.Scheme == "net.pipe") { NamedPipeTransportBindingElement ipcBindingElement = new NamedPipeTransportBindingElement(); ipcBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier; endpoints = QueryMexEndpoint(mexAddress, ipcBindingElement); } return endpoints.ToArray(); }
void RunApplication() { using (Mutex mutex = new Mutex(false, @"Global\Incinerator.Application.Mutex")) { if (mutex.WaitOne(0)) { try { using (MainService service = new MainService()) { NamedPipeTransportBindingElement transport = new NamedPipeTransportBindingElement(); transport.ConnectionPoolSettings.IdleTimeout = TimeSpan.MaxValue; CustomBinding binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), transport); binding.OpenTimeout = TimeSpan.FromSeconds(3.0); binding.ReceiveTimeout = TimeSpan.MaxValue; binding.SendTimeout = TimeSpan.FromSeconds(6.0); binding.CloseTimeout = TimeSpan.FromSeconds(3.0); ServiceHost host = new ServiceHost(service); host.AddServiceEndpoint(typeof(IIncinerateService), binding, "net.pipe://IncinerateService/incinerate"); host.Open(); Logger.Info("Server Started"); m_ExitSignal.WaitOne(); host.Close(); } } catch (Exception e) { Logger.Error(e); if (m_IsService) Stop(); } finally { // dispose all objects } } else { Logger.Info("Cannot run multiple instances of " + ServiceID); } } }