コード例 #1
0
 public JsonRpcHttpBinding()
     : base()
 {
     transport = new HttpTransportBindingElement();
     encoding = new WebMessageEncodingBindingElement();
     encoding.ContentTypeMapper = new JsonRpcRawMapper();
 }
コード例 #2
0
        private static void CreateHttpGetChannelDispatcher(ServiceHostBase host, Uri listenUri, MetadataSet metadata)
        {
            //创建Binding
            TextMessageEncodingBindingElement messageEncodingElement = new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.None };
            HttpTransportBindingElement transportElement = new HttpTransportBindingElement();
            Utility.SetPropertyValue(transportElement, "Method", "GET");
            Binding binding = new CustomBinding(messageEncodingElement, transportElement);

            //创建ChannelListener
            IChannelListener listener = binding.BuildChannelListener<IReplyChannel>(listenUri, string.Empty, ListenUriMode.Explicit, new BindingParameterCollection());
            ChannelDispatcher dispatcher = new ChannelDispatcher(listener, "ServiceMetadataBehaviorHttpGetBinding", binding) { MessageVersion = binding.MessageVersion };

            //创建EndpointDispatcher
            EndpointDispatcher endpoint = new EndpointDispatcher(new EndpointAddress(listenUri), "IHttpGetMetadata", "http://www.artech.com/");

            //创建DispatchOperation,并设置DispatchMessageFormatter和OperationInvoker
            DispatchOperation operation = new DispatchOperation(endpoint.DispatchRuntime, "Get", "*", "*");
            operation.Formatter = Utility.CreateInstance<IDispatchMessageFormatter>(MessageOperationFormatterType, Type.EmptyTypes, new object[0]);
            MethodInfo method = typeof(IHttpGetMetadata).GetMethod("Get");
            operation.Invoker = Utility.CreateInstance<IOperationInvoker>(SyncMethodInvokerType, new Type[] { typeof(MethodInfo) }, new object[] { method });
            endpoint.DispatchRuntime.Operations.Add(operation);

            //设置SingletonInstanceContext和InstanceContextProvider
            MetadataProvisionService serviceInstance = new MetadataProvisionService(metadata);
            endpoint.DispatchRuntime.SingletonInstanceContext = new InstanceContext(host, serviceInstance);
            endpoint.DispatchRuntime.InstanceContextProvider = Utility.CreateInstance<IInstanceContextProvider>(SingletonInstanceContextProviderType, new Type[] { typeof(DispatchRuntime) }, new object[] { endpoint.DispatchRuntime });
            dispatcher.Endpoints.Add(endpoint);

            //设置ContractFilter和AddressFilter
            endpoint.ContractFilter = new MatchAllMessageFilter();
            endpoint.AddressFilter = new MatchAllMessageFilter();

            host.ChannelDispatchers.Add(dispatcher);
        }
コード例 #3
0
        public static CustomBinding GetBinding()
        {
            // Same binding should be used in both service and service client.
            //var binding = new BasicHttpBinding();
            //binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            //SetTimeOuts(binding);
            //return binding;

            // Instantiate message encoding element and configure
            TextMessageEncodingBindingElement text = new TextMessageEncodingBindingElement();
            text.MessageVersion = MessageVersion.Soap11;
            text.ReaderQuotas.MaxStringContentLength = int.MaxValue;

            // Instantiate transport element and configure
            HttpTransportBindingElement http = new HttpTransportBindingElement();
            http.TransferMode = TransferMode.Buffered;
            http.UseDefaultWebProxy = true;

            CustomBinding binding = new CustomBinding();
            binding.Name = "MonoscapeHttpBinding";
            binding.Elements.Add(text);
            binding.Elements.Add(http);
            SetTimeOuts(binding);

            return binding;
        }
 private void ConfigureAuthentication(HttpTransportBindingElement http)
 {
     http.AuthenticationScheme = HttpClientCredentialTypeHelper.MapToAuthenticationScheme(this.clientCredentialType);
     http.ProxyAuthenticationScheme = HttpProxyCredentialTypeHelper.MapToAuthenticationScheme(this.proxyCredentialType);
     http.Realm = this.Realm;
     http.ExtendedProtectionPolicy = this.extendedProtectionPolicy;
 }
 private void DisableAuthentication(HttpTransportBindingElement http)
 {
     http.AuthenticationScheme = AuthenticationSchemes.Anonymous;
     http.ProxyAuthenticationScheme = AuthenticationSchemes.Anonymous;
     http.Realm = "";
     http.ExtendedProtectionPolicy = this.extendedProtectionPolicy;
 }
コード例 #6
0
		public void CanBuildChannelFactory ()
		{
			// with HttpTransport
			var m = new WebMessageEncodingBindingElement ();
			Assert.IsTrue (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#1");
			Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#2");
			Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#3");
			Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#4");

			// actually they are from transport
			var h = new HttpTransportBindingElement ();
			Assert.IsTrue (h.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#5");
			Assert.IsFalse (h.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#6");
			Assert.IsFalse (h.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#7");
			Assert.IsFalse (h.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#8");

			// with TcpTransport
			Assert.IsFalse (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#9");
			Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#10");
			Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#11");
			Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#12");

			// ... yes, actually they are from transport
			var t = new TcpTransportBindingElement ();
			Assert.IsFalse (t.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#13");
			Assert.IsFalse (t.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#14");
			Assert.IsFalse (t.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#15");
			Assert.IsFalse (t.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#16");
		}
 private void InitializeFrom(HttpTransportBindingElement transport, MessageEncodingBindingElement encoding, System.ServiceModel.Channels.TransactionFlowBindingElement txFlow, System.ServiceModel.Channels.ReliableSessionBindingElement session)
 {
     this.BypassProxyOnLocal = transport.BypassProxyOnLocal;
     this.HostNameComparisonMode = transport.HostNameComparisonMode;
     this.MaxBufferPoolSize = transport.MaxBufferPoolSize;
     this.MaxReceivedMessageSize = transport.MaxReceivedMessageSize;
     this.ProxyAddress = transport.ProxyAddress;
     this.UseDefaultWebProxy = transport.UseDefaultWebProxy;
     if (encoding is TextMessageEncodingBindingElement)
     {
         this.MessageEncoding = WSMessageEncoding.Text;
         TextMessageEncodingBindingElement element = (TextMessageEncodingBindingElement) encoding;
         this.TextEncoding = element.WriteEncoding;
         this.ReaderQuotas = element.ReaderQuotas;
     }
     else if (encoding is MtomMessageEncodingBindingElement)
     {
         this.messageEncoding = WSMessageEncoding.Mtom;
         MtomMessageEncodingBindingElement element2 = (MtomMessageEncodingBindingElement) encoding;
         this.TextEncoding = element2.WriteEncoding;
         this.ReaderQuotas = element2.ReaderQuotas;
     }
     this.TransactionFlow = txFlow.Transactions;
     this.reliableSession.Enabled = session != null;
     if (session != null)
     {
         this.session.InactivityTimeout = session.InactivityTimeout;
         this.session.Ordered = session.Ordered;
     }
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: porter1130/MyTest
        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();
            }
        }
 private static void ConfigureAuthentication(HttpTransportBindingElement http, HttpTransportSecurity transportSecurity)
 {
     transportSecurity.clientCredentialType = HttpClientCredentialTypeHelper.MapToClientCredentialType(http.AuthenticationScheme);
     transportSecurity.proxyCredentialType = HttpProxyCredentialTypeHelper.MapToProxyCredentialType(http.ProxyAuthenticationScheme);
     transportSecurity.Realm = http.Realm;
     transportSecurity.extendedProtectionPolicy = http.ExtendedProtectionPolicy;
 }
コード例 #10
0
ファイル: Output.cs プロジェクト: porter1130/MyTest
        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();
            }
        }
コード例 #11
0
ファイル: reply.cs プロジェクト: alesliehughes/olive
	public static void Main ()
	{
		HttpTransportBindingElement el =
			new HttpTransportBindingElement ();
		BindingContext bc = new BindingContext (
			new CustomBinding (),
			new BindingParameterCollection (),
			new Uri ("http://localhost:37564"),
			String.Empty, ListenUriMode.Explicit);
		IChannelListener<IReplyChannel> listener =
			el.BuildChannelListener<IReplyChannel> (bc);

		listener.Open ();

		IReplyChannel reply = listener.AcceptChannel ();

		reply.Open ();

		if (!reply.WaitForRequest (TimeSpan.FromSeconds (10))) {
			Console.WriteLine ("No request reached here.");
			return;
		}
		Console.WriteLine ("Receiving request ...");
		RequestContext ctx = reply.ReceiveRequest ();
		if (ctx == null)
			return;
		Console.WriteLine ("Starting reply ...");
		ctx.Reply (Message.CreateMessage (MessageVersion.Default, "Ack"));
	}
コード例 #12
0
ファイル: service.cs プロジェクト: spzenk/sfdocsamples
        // 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();
            }
        }
 private static bool GetSecurityModeFromTransport(HttpTransportBindingElement http, HttpTransportSecurity transportSecurity, out UnifiedSecurityMode mode)
 {
     mode = UnifiedSecurityMode.None;
     if (http == null)
     {
         return false;
     }
     if (http is HttpsTransportBindingElement)
     {
         mode = UnifiedSecurityMode.TransportWithMessageCredential | UnifiedSecurityMode.Transport;
         BasicHttpSecurity.EnableTransportSecurity((HttpsTransportBindingElement) http, transportSecurity);
     }
     else if (HttpTransportSecurity.IsDisabledTransportAuthentication(http))
     {
         mode = UnifiedSecurityMode.Message | UnifiedSecurityMode.None;
     }
     else
     {
         if (!BasicHttpSecurity.IsEnabledTransportAuthentication(http, transportSecurity))
         {
             return false;
         }
         mode = UnifiedSecurityMode.TransportCredentialOnly;
     }
     return true;
 }
コード例 #14
0
ファイル: Service.cs プロジェクト: EdiCarlos/MyPractices
        public static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8000/servicesamplemodel/service");
            using (ServiceHost host = new ServiceHost(typeof(Service), baseAddress))
            {
                ReliableSessionBindingElement reliableBinding = new ReliableSessionBindingElement();
                reliableBinding.Ordered = true;

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

                CustomBinding customBinding = new CustomBinding(reliableBinding, httpBindingElement);

                host.AddServiceEndpoint(typeof(ICalculator), customBinding, "");

                host.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

            }
        }
コード例 #15
0
ファイル: samplesvc10.cs プロジェクト: alesliehughes/olive
	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 ();
	}
コード例 #16
0
ファイル: request.cs プロジェクト: alesliehughes/olive
	public static void Main ()
	{
		HttpTransportBindingElement el =
			new HttpTransportBindingElement ();
		IChannelFactory<IRequestChannel> factory =
			el.BuildChannelFactory<IRequestChannel> (
				new BindingContext (new CustomBinding (),
					new BindingParameterCollection ()));

		factory.Open ();

		IRequestChannel request = factory.CreateChannel (
			new EndpointAddress ("http://localhost:37564"));

		request.Open ();

		using (XmlWriter w = XmlWriter.Create (Console.Out)) {
			Message.CreateMessage (MessageVersion.Default, "Echo")
				.WriteMessage (w);
		}
		Console.WriteLine ();

		Message msg = request.Request (
			Message.CreateMessage (MessageVersion.Default, "Echo"),
			TimeSpan.FromSeconds (15));
		using (XmlWriter w = XmlWriter.Create (Console.Out)) {
			msg.WriteMessage (w);
		}
	}
コード例 #17
0
ファイル: ProxyClient.cs プロジェクト: JiahuiGuo/openPDC
        public static DuplexServiceClient GetDuplexServiceProxyClient()
        {
            string baseServiceUrl = Application.Current.Resources["BaseServiceUrl"].ToString();
            EndpointAddress address = new EndpointAddress(baseServiceUrl + "DuplexService/PhasorDataDuplexService.svc");
            CustomBinding binding;
            if (HtmlPage.Document.DocumentUri.Scheme.ToLower().StartsWith("https"))
            {
                HttpsTransportBindingElement httpsTransportBindingElement = new HttpsTransportBindingElement();
                httpsTransportBindingElement.MaxReceivedMessageSize = int.MaxValue;
                binding = new CustomBinding(
                                    new PollingDuplexBindingElement(),
                                    new BinaryMessageEncodingBindingElement(),
                                    httpsTransportBindingElement
                                    );
            }
            else
            {
                HttpTransportBindingElement httpTransportBindingElement = new HttpTransportBindingElement();
                httpTransportBindingElement.MaxReceivedMessageSize = int.MaxValue;	// 65536 * 50;
                binding = new CustomBinding(
                                    new PollingDuplexBindingElement(),
                                    new BinaryMessageEncodingBindingElement(),
                                    httpTransportBindingElement
                                    );
            }

            binding.CloseTimeout = new TimeSpan(0, 20, 0);
            binding.OpenTimeout = new TimeSpan(0, 20, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 20, 0);
            binding.SendTimeout = new TimeSpan(0, 20, 0);

            return new DuplexServiceClient(binding, address);
        }
コード例 #18
0
 private void DisableAuthentication(HttpTransportBindingElement http)
 {
     http.AuthenticationScheme = AuthenticationSchemes.Anonymous;
     http.Realm = DefaultRealm;
     //ExtendedProtectionPolicy is always copied - even for security mode None, Message and TransportWithMessageCredential,
     //because the settings for ExtendedProtectionPolicy are always below the <security><transport> element
     //http.ExtendedProtectionPolicy = this.extendedProtectionPolicy;
 }
 internal void ConfigureTransportAuthentication(HttpTransportBindingElement http)
 {
     if (this.clientCredentialType == HttpClientCredentialType.Certificate)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CertificateUnsupportedForHttpTransportCredentialOnly")));
     }
     this.ConfigureAuthentication(http);
 }
 private static HttpsTransportBindingElement CreateHttpsFromHttp(HttpTransportBindingElement http)
 {
     if (http == null)
     {
         return new HttpsTransportBindingElement();
     }
     return HttpsTransportBindingElement.CreateFromHttpBindingElement(http);
 }
コード例 #21
0
        internal HttpBindingBase()
        {
            _httpTransport = new HttpTransportBindingElement();
            _httpsTransport = new HttpsTransportBindingElement();

            _textEncoding = new TextMessageEncodingBindingElement();
            _textEncoding.MessageVersion = MessageVersion.Soap11;
            _httpsTransport.WebSocketSettings = _httpTransport.WebSocketSettings;
        }
 private static CustomBinding CreateGetBinding(HttpTransportBindingElement httpTransport)
 {
     TextMessageEncodingBindingElement element = new TextMessageEncodingBindingElement {
         MessageVersion = MessageVersion.None
     };
     httpTransport.Method = "GET";
     httpTransport.InheritBaseAddressSettings = true;
     return new CustomBinding(new BindingElement[] { element, httpTransport });
 }
コード例 #23
0
        private void Initialize()
        {
            _securityBindingElement = CreateSecurityBindingElement();

            _textEncodingBindingElement = CreateTextEncodingBindingElement();

            //_httpsTransportBindingElement = CreateHttpsTransportBindingElement();
            _httpTransportBindingElement = CreateHttpTransportBindingElement();
        }
 protected override void ApplyTransportSecurity(HttpTransportBindingElement transport)
 {
     transport.AuthenticationScheme = AuthenticationSchemes.Anonymous;
     
     var element = transport as HttpsTransportBindingElement;
     if (element != null)
     {
         element.RequireClientCertificate = true;
     }
 }
コード例 #25
0
        private HttpTransportBindingElement CreateHttpTransportBindingElement()
        {
            HttpTransportBindingElement transportBindingElement = new HttpTransportBindingElement();

            transportBindingElement.MaxBufferSize = 524288;
            transportBindingElement.MaxReceivedMessageSize = 200000000;
            transportBindingElement.MaxBufferSize = 200000000;

            return transportBindingElement;
        }
コード例 #26
0
        internal static void DisableTransportAuthentication(this HttpTransportSecurity httpTransportSecurity, HttpTransportBindingElement httpTransportBindingElement)
        {
            Debug.Assert(httpTransportSecurity != null, "httpTransportSecurity cannot be null");
            Debug.Assert(httpTransportBindingElement != null, "httpTransportBindingElement cannot be null");

            httpTransportBindingElement.AuthenticationScheme = AuthenticationSchemes.Anonymous;
            httpTransportBindingElement.ProxyAuthenticationScheme = AuthenticationSchemes.Anonymous;
            httpTransportBindingElement.Realm = String.Empty;
            httpTransportBindingElement.ExtendedProtectionPolicy = httpTransportSecurity.ExtendedProtectionPolicy;
        }
コード例 #27
0
        private static void ConfigureAuthentication(this HttpTransportSecurity httpTransportSecurity, HttpTransportBindingElement httpTransportBindingElement)
        {
            Debug.Assert(httpTransportSecurity != null, "httpTransportSecurity cannot be null");
            Debug.Assert(httpTransportBindingElement != null, "httpTransportBindingElement cannot be null");

            httpTransportBindingElement.AuthenticationScheme = HttpClientCredentialTypeHelper.MapToAuthenticationScheme(httpTransportSecurity.ClientCredentialType);
            httpTransportBindingElement.ProxyAuthenticationScheme = HttpProxyCredentialTypeHelper.MapToAuthenticationScheme(httpTransportSecurity.ProxyCredentialType);
            httpTransportBindingElement.Realm = httpTransportSecurity.Realm;
            httpTransportBindingElement.ExtendedProtectionPolicy = httpTransportSecurity.ExtendedProtectionPolicy;
        }
コード例 #28
0
    public static void IRequestChannel_Http_CustomBinding()
    {
        try
        {
            BindingElement[] bindingElements = new BindingElement[2];
            bindingElements[0] = new TextMessageEncodingBindingElement();
            bindingElements[1] = new HttpTransportBindingElement();
            CustomBinding binding = new CustomBinding(bindingElements);

            // Create the channel factory for the request-reply message exchange pattern.
            IChannelFactory<IRequestChannel> factory =
            binding.BuildChannelFactory<IRequestChannel>(
                             new BindingParameterCollection());
            factory.Open();

            // Create the channel.
            IRequestChannel channel = factory.CreateChannel(
               new EndpointAddress(Endpoints.DefaultCustomHttp_Address));
            channel.Open();

            // Create the Message object to send to the service.
            Message requestMessage = Message.CreateMessage(
                binding.MessageVersion,
                action,
                new CustomBodyWriter(clientMessage));

            // Send the Message and receive the Response.
            Message replyMessage = channel.Request(requestMessage);
            string replyMessageAction = replyMessage.Headers.Action;

            if (!string.Equals(replyMessageAction, action + "Response"))
            {
                Assert.True(false, String.Format("A response was received from the Service but it was not the expected Action, expected: {0} actual: {1}", action + "Response", replyMessageAction));
            }


            var replyReader = replyMessage.GetReaderAtBodyContents();
            string actualResponse = replyReader.ReadElementContentAsString();
            string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply.";
            if (!string.Equals(actualResponse, expectedResponse))
            {
                Assert.True(false, String.Format("Actual MessageBodyContent from service did not match the expected MessageBodyContent, expected: {0} actual: {1}", expectedResponse, actualResponse));
            }

            replyMessage.Close();
            channel.Close();
            factory.Close();
        }

        catch (Exception ex)
        {
            Assert.True(false, String.Format("Unexpected exception was caught: {0}", ex.ToString()));
        }
    }
コード例 #29
0
        public HttpCookieSessionBinding()
            : base()
        {
            sessionElement = new HttpCookieSessionBindingElement();

            transportElement = new HttpTransportBindingElement();
            transportElement.AllowCookies = true;

            encodingElement = new TextMessageEncodingBindingElement();
            encodingElement.MessageVersion = MessageVersion.Soap11WSAddressing10;
        }
 protected override void ApplyTransportSecurity(HttpTransportBindingElement transport)
 {
     if (this._clientCredentialType == HttpClientCredentialType.Basic)
     {
         transport.AuthenticationScheme = AuthenticationSchemes.Basic;
     }
     else
     {
         transport.AuthenticationScheme = AuthenticationSchemes.Digest;
     }
 }