当前位置: 首页>>代码示例>>C#>>正文


C# Channels.CustomBinding类代码示例

本文整理汇总了C#中System.ServiceModel.Channels.CustomBinding的典型用法代码示例。如果您正苦于以下问题:C# CustomBinding类的具体用法?C# CustomBinding怎么用?C# CustomBinding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CustomBinding类属于System.ServiceModel.Channels命名空间,在下文中一共展示了CustomBinding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8773/WSHttpService");

            WSHttpBinding binding = new WSHttpBinding();

            binding.Name = "WSHttp_Binding";
            binding.HostNameComparisonMode = HostNameComparisonMode.WeakWildcard;
            CustomBinding customBinding = new CustomBinding(binding);
            SymmetricSecurityBindingElement securityBinding = (SymmetricSecurityBindingElement)customBinding.Elements.Find<SecurityBindingElement>();

            /// Change the MaxClockSkew to 2 minutes on both service and client settings.
            TimeSpan newClockSkew = new TimeSpan(0, 2, 0);

            securityBinding.LocalServiceSettings.MaxClockSkew = newClockSkew;
            securityBinding.LocalClientSettings.MaxClockSkew = newClockSkew;

            using (ServiceHost host = new ServiceHost(typeof(WSHttpService), baseAddress))
            {
                host.AddServiceEndpoint(typeof(IWSHttpService), customBinding, "http://localhost:8773/WSHttpService/mex");
                // Enable metadata publishing.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);
                host.Open();

                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                // Close the ServiceHost.
                host.Close();
            }
        }
开发者ID:zabidin901,项目名称:ReplayAttackWCFProtoType,代码行数:35,代码来源:Program.cs

示例2: SameBinding_Binary_EchoComplexString

    public static void SameBinding_Binary_EchoComplexString()
    {
        CustomBinding binding = null;
        ChannelFactory<IWcfService> factory = null;
        EndpointAddress endpointAddress = null;
        IWcfService serviceProxy = null;
        ComplexCompositeType compositeObject = null;
        ComplexCompositeType result = null;

        try
        {
            // *** SETUP *** \\
            binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
            endpointAddress = new EndpointAddress(Endpoints.HttpBinary_Address);
            factory = new ChannelFactory<IWcfService>(binding, endpointAddress);
            serviceProxy = factory.CreateChannel();
            compositeObject = ScenarioTestHelpers.GetInitializedComplexCompositeType();

            // *** EXECUTE *** \\
            result = serviceProxy.EchoComplex(compositeObject);

            // *** VALIDATE *** \\
            Assert.True(compositeObject.Equals(result), String.Format("    Error: expected response from service: '{0}' Actual was: '{1}'", compositeObject, result));

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
开发者ID:roncain,项目名称:wcf,代码行数:34,代码来源:BinaryEncodingTests.4.0.0.cs

示例3: Main

	public static void Main ()
	{
		SymmetricSecurityBindingElement sbe =
			new SymmetricSecurityBindingElement ();
		sbe.ProtectionTokenParameters =
			new SslSecurityTokenParameters ();
		ServiceHost host = new ServiceHost (typeof (Foo));
		HttpTransportBindingElement hbe =
			new HttpTransportBindingElement ();
		CustomBinding binding = new CustomBinding (sbe, hbe);
		binding.ReceiveTimeout = TimeSpan.FromSeconds (5);
		host.AddServiceEndpoint ("IFoo",
			binding, new Uri ("http://localhost:8080"));
		ServiceCredentials cred = new ServiceCredentials ();
		cred.SecureConversationAuthentication.SecurityStateEncoder =
			new MyEncoder ();
		cred.ServiceCertificate.Certificate =
			new X509Certificate2 ("test.pfx", "mono");
		cred.ClientCertificate.Authentication.CertificateValidationMode =
			X509CertificateValidationMode.None;
		host.Description.Behaviors.Add (cred);
		host.Description.Behaviors.Find<ServiceDebugBehavior> ()
			.IncludeExceptionDetailInFaults = true;
//		foreach (ServiceEndpoint se in host.Description.Endpoints)
//			se.Behaviors.Add (new StdErrInspectionBehavior ());
		ServiceMetadataBehavior smb = new ServiceMetadataBehavior ();
		smb.HttpGetEnabled = true;
		smb.HttpGetUrl = new Uri ("http://localhost:8080/wsdl");
		host.Description.Behaviors.Add (smb);
		host.Open ();
		Console.WriteLine ("Hit [CR] key to close ...");
		Console.ReadLine ();
		host.Close ();
	}
开发者ID:alesliehughes,项目名称:olive,代码行数:34,代码来源:samplesvc10.cs

示例4: CreateServiceHost

        protected override ServiceHost CreateServiceHost(Type serviceType, 
                                                         Uri[] baseAddresses)
        {
            WebServiceHost2Ex webServiceHost2Ex =
                new WebServiceHost2Ex(serviceType, baseAddresses);

            //new code
            Uri[] defaultAddresses = new Uri[1];
            defaultAddresses[0] = baseAddresses[0];

            // Bind up the JSONP extension
            CustomBinding cb = new CustomBinding(new WebHttpBinding());
            cb.Name = "JSONPBinding";

            // Replace the current MessageEncodingBindingElement with the JSONP element
            var currentEncoder = cb.Elements.Find<MessageEncodingBindingElement>();
            if (currentEncoder != default(MessageEncodingBindingElement))
            {
                cb.Elements.Remove(currentEncoder);
                cb.Elements.Insert(0, new JSONPBindingElement());
            }

            webServiceHost2Ex.AddServiceEndpoint(serviceType.GetInterfaces()[0], cb, defaultAddresses[0]);

            return webServiceHost2Ex;
        }
开发者ID:ergin-a1,项目名称:REST_API_Prototype_NET35,代码行数:26,代码来源:ServiceHostFactory2Ex.cs

示例5: Main

        // Host the service within this EXE console application.
        public static void Main()
        {
            Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");

            // Create a ServiceHost for the CalculatorService type and provide the base address.
            using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
            {
                // Create a custom binding containing two binding elements
                ReliableSessionBindingElement reliableSession = new ReliableSessionBindingElement();
                reliableSession.Ordered = true;

                HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
                httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
                httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

                CustomBinding binding = new CustomBinding(reliableSession, httpTransport);

                // Add an endpoint using that binding
                serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, "");
              
                // Open the ServiceHost to create listeners and start listening for messages.
                serviceHost.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();
            }
        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:31,代码来源:service.cs

示例6: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                //string xx = textBox1.Text;
                CustomBinding binding = new CustomBinding(new CustomTextMessageBindingElement("iso-8859-1", "text/xml", MessageVersion.Soap11), new HttpTransportBindingElement());
                FVEWebService.FVEWebServicePortTypeClient prueba = new FVEWebService.FVEWebServicePortTypeClient();
                prueba.Endpoint.Binding = binding;

                FVEWebService.Productos prod = new FVEWebService.Productos();
                
                prod = prueba.foBuscarProducto(20165501);
                MessageBox.Show(prod.prod_nom);
                
                
               
               
                ////string Arreglo =  prueba.Prod();
                //PruebaWS.Productos Arreglo = prueba.foObtenerProductos();
                //if (Arreglo.Length > 0)
                //{
                //    MessageBox.Show("Hay: " + Arreglo.Length + " productos");
                //}
                //else {
                //    MessageBox.Show("No Hay");
                //}

                pictureBox1.Load("http://www.punk-hxc.com/especiales/punk-hardcore.jpg");

            }catch(Exception ex){
                MessageBox.Show(ex.Message);
            }
        }
开发者ID:javierxbrenes1,项目名称:fve_mantenimientoProd,代码行数:34,代码来源:UIMantenimiento.cs

示例7: ClientBaseOfT_ClientCredentials

    public static void ClientBaseOfT_ClientCredentials()
    {
        MyClientBase client = null;
        ClientCredentials clientCredentials = null;

        try
        {
            // *** SETUP *** \\
            CustomBinding customBinding = new CustomBinding();
            customBinding.Elements.Add(new TextMessageEncodingBindingElement());
            customBinding.Elements.Add(new HttpTransportBindingElement());

            string endpoint = Endpoints.HttpSoap12_Address;
            client = new MyClientBase(customBinding, new EndpointAddress(endpoint));

            // *** EXECUTE *** \\
            clientCredentials = client.ClientCredentials;

            // *** VALIDATE *** \\
            Assert.True(clientCredentials != null, "ClientCredentials should not be null");
            Assert.True(clientCredentials.ClientCertificate != null, "ClientCredentials.ClientCertificate should not be null");
            Assert.True(clientCredentials.ServiceCertificate != null, "ClientCredentials.ServiceCertificate should not be null");
            Assert.True(clientCredentials.HttpDigest != null, "ClientCredentials.HttpDigest should not be null");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();

        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects(client);
        }
    }
开发者ID:roncain,项目名称:wcf,代码行数:34,代码来源:ClientBaseTests.4.4.0.cs

示例8: RunCodeUnderDiscoveryHost

	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri dHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action)
	{
		var aEndpoint = new UdpAnnouncementEndpoint (DiscoveryVersion.WSDiscoveryApril2005, new Uri ("soap.udp://239.255.255.250:3802/"));
		var dbinding = new CustomBinding (new HttpTransportBindingElement ());
		var dAddress = new EndpointAddress (dHostUri);
		var dEndpoint = new DiscoveryEndpoint (dbinding, dAddress);

		var ib = new InspectionBehavior ();
		ib.RequestReceived += delegate (ref Message msg, IClientChannel
channel, InstanceContext instanceContext) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			return null;
			};
		ib.ReplySending += delegate (ref Message msg, object o) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			};

		dEndpoint.Behaviors.Add (ib);
		aEndpoint.Behaviors.Add (ib);

		action (serviceUri, aEndpoint, dEndpoint);
	}
开发者ID:alesliehughes,项目名称:olive,代码行数:26,代码来源:sample-service2.cs

示例9: GetCustomBinding

 //Used by live contacts channel and Solr search and RelatedItems
 public static CustomBinding GetCustomBinding(Binding source)
 {
     CustomBinding result = new CustomBinding(source);
     WebMessageEncodingBindingElement element = result.Elements.Find<WebMessageEncodingBindingElement>();
     element.ContentTypeMapper = new RawMapper();
     return result;
 }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:8,代码来源:RawMapper.cs

示例10: Main

        static void Main(string[] args)
        {
            try {
                BindingElement[] bindingElements = new BindingElement[2];
                bindingElements[0] = new TextMessageEncodingBindingElement();
                bindingElements[1] = new HttpTransportBindingElement();

                CustomBinding binding = new CustomBinding(bindingElements);

                IChannelListener<IReplyChannel> listener=binding.BuildChannelListener<IReplyChannel>(new Uri("http://localhost:9090/RequestReplyService"),new BindingParameterCollection());
                listener.Open();

                IReplyChannel replyChannel = listener.AcceptChannel();
                replyChannel.Open();
                Console.WriteLine("starting to receive message....");

                RequestContext requestContext = replyChannel.ReceiveRequest();
                Console.WriteLine("Received a Message, action:{0},body:{1}", requestContext.RequestMessage.Headers.Action,
                                    requestContext.RequestMessage.GetBody<string>());
                Message message = Message.CreateMessage(binding.MessageVersion, "response", "response Message");
                requestContext.Reply(message);

                requestContext.Close();
                replyChannel.Close();
                listener.Close();

            }
            catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
            finally {
                Console.Read();
            }
        }
开发者ID:porter1130,项目名称:MyTest,代码行数:34,代码来源:Program.cs

示例11: SameBinding_Binary_EchoComplexString

    public static void SameBinding_Binary_EchoComplexString()
    {
        string variationDetails = "Client:: CustomBinding/BinaryEncoder/Http\nServer:: CustomBinding/BinaryEncoder/Http";
        StringBuilder errorBuilder = new StringBuilder();
        bool success = false;

        try
        {
            CustomBinding binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
            ChannelFactory<IWcfService> factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(Endpoints.HttpBinary_Address));
            IWcfService serviceProxy = factory.CreateChannel();

            ComplexCompositeType compositeObject = ScenarioTestHelpers.GetInitializedComplexCompositeType();

            ComplexCompositeType result = serviceProxy.EchoComplex(compositeObject);
            success = compositeObject.Equals(result);

            if (!success)
            {
                errorBuilder.AppendLine(String.Format("    Error: expected response from service: '{0}' Actual was: '{1}'", compositeObject, result));
            }
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("    Error: Unexpected exception was caught while doing the basic echo test for variation...\n'{0}'\nException: {1}", variationDetails, ex.ToString()));
            for (Exception innerException = ex.InnerException; innerException != null; innerException = innerException.InnerException)
            {
                errorBuilder.AppendLine(String.Format("Inner exception: {0}", innerException.ToString()));
            }
        }

        Assert.True(errorBuilder.Length == 0, errorBuilder.ToString());
    }
开发者ID:weshaggard,项目名称:wcf,代码行数:33,代码来源:BinaryEncodingTests.4.0.0.cs

示例12: DefaultSettings_Https_Text_Echo_RoundTrips_String

    public static void DefaultSettings_Https_Text_Echo_RoundTrips_String()
    {
        string testString = "Hello";
        CustomBinding binding = null;
        ChannelFactory<IWcfService> factory = null;
        IWcfService serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            binding = new CustomBinding(new TextMessageEncodingBindingElement(), new HttpsTransportBindingElement());
            factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(Endpoints.HttpsSoap12_Address));
            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.NotNull(result);
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
开发者ID:roncain,项目名称:wcf,代码行数:31,代码来源:CustomBindingTests.4.1.0.cs

示例13: DefaultSettings_Tcp_Binary_Echo_RoundTrips_String

    public static void DefaultSettings_Tcp_Binary_Echo_RoundTrips_String()
    {
        string testString = "Hello";
        ChannelFactory<IWcfService> factory = null;
        IWcfService serviceProxy = null;

        try
        {
            // *** SETUP *** \\
            CustomBinding binding = new CustomBinding(
                new SslStreamSecurityBindingElement(),
                new BinaryMessageEncodingBindingElement(),
                new TcpTransportBindingElement());

            var endpointIdentity = new DnsEndpointIdentity(Endpoints.Tcp_CustomBinding_SslStreamSecurity_HostName);
            factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(new Uri(Endpoints.Tcp_CustomBinding_SslStreamSecurity_Address), endpointIdentity));
            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
开发者ID:roncain,项目名称:wcf,代码行数:34,代码来源:CustomBindingTests.4.1.0.cs

示例14: Main

        static void Main(string[] args)
        {
            try
            {
                BindingElement[] bindingElements = new BindingElement[2];
                bindingElements[0] = new TextMessageEncodingBindingElement();
                bindingElements[1] = new HttpTransportBindingElement();

                CustomBinding binding = new CustomBinding(bindingElements);
                using (Message message = Message.CreateMessage(binding.MessageVersion, "sendMessage", "Message Body"))
                {
                    IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
                    factory.Open();

                    IRequestChannel requestChannel = factory.CreateChannel(new EndpointAddress("http://localhost:9090/RequestReplyService"));
                    requestChannel.Open();
                    Message response = requestChannel.Request(message);

                    Console.WriteLine("Successful send message!");

                    Console.WriteLine("Receive a return message, action: {0}, body: {1}", response.Headers.Action, response.GetBody<String>());
                    requestChannel.Close();
                    factory.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally {
                Console.Read();
            }
        }
开发者ID:porter1130,项目名称:MyTest,代码行数:33,代码来源:Output.cs

示例15: ServiceContract_TypedProxy_AsyncBeginEnd_Call

 public static void ServiceContract_TypedProxy_AsyncBeginEnd_Call()
 {
     CustomBinding customBinding = new CustomBinding();
     customBinding.Elements.Add(new TextMessageEncodingBindingElement());
     customBinding.Elements.Add(new HttpTransportBindingElement());
     ServiceContract_TypedProxy_AsyncBeginEnd_Call(customBinding, Endpoints.DefaultCustomHttp_Address, "ServiceContract_TypedProxy_AsyncBeginEnd_Call");
 }
开发者ID:TerabyteX,项目名称:wcf,代码行数:7,代码来源:TypedProxyTests.cs


注:本文中的System.ServiceModel.Channels.CustomBinding类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。