private void CreateEndpoints() { Type contractType = ServiceUtility.GetContractType(ImplementedContracts); AuthenticationSchemes oneAuthScheme; ClientRequestServiceBehaviorAttribute.GetAllAuthenticationSchemes(out oneAuthScheme); foreach (Uri baseAddress in this.m_baseAddresses) { WebHttpBinding binding = new WebHttpBinding { AllowCookies = true, ReceiveTimeout = TimeSpan.FromHours(1), SendTimeout = TimeSpan.FromHours(1), OpenTimeout = TimeSpan.FromHours(1), CloseTimeout = TimeSpan.FromHours(1), MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas { MaxArrayLength = int.MaxValue, MaxBytesPerRead = 2048, MaxDepth = int.MaxValue, MaxNameTableCharCount = int.MaxValue, MaxStringContentLength = int.MaxValue, } }; if (object.ReferenceEquals(baseAddress.Scheme, Uri.UriSchemeHttps)) { binding.Security.Mode = WebHttpSecurityMode.Transport; } else if (object.ReferenceEquals(baseAddress.Scheme, Uri.UriSchemeHttp)) { binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly; } else if ((oneAuthScheme != AuthenticationSchemes.None) && (oneAuthScheme != AuthenticationSchemes.Anonymous)) { binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly; } else { binding.Security.Mode = WebHttpSecurityMode.None; } binding.Security.Transport.ClientCredentialType = ServiceUtility.ClientCredentialTypeFromAuthenticationScheme(oneAuthScheme); AddServiceEndpoint(contractType, binding, baseAddress); } }
private void CreateEndpoints() { var contractType = ServiceUtility.GetContractType(ImplementedContracts); AuthenticationSchemes oneAuthScheme; ClientRequestServiceBehaviorAttribute.GetAllAuthenticationSchemes(out oneAuthScheme); foreach (var baseAddress in this.m_baseAddresses) { var binding = new BasicHttpBinding { AllowCookies = true, ReceiveTimeout = TimeSpan.FromHours(1), SendTimeout = TimeSpan.FromHours(1), OpenTimeout = TimeSpan.FromHours(1), CloseTimeout = TimeSpan.FromHours(1), MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas { MaxArrayLength = int.MaxValue, MaxBytesPerRead = 2048, MaxDepth = int.MaxValue, MaxNameTableCharCount = int.MaxValue, MaxStringContentLength = int.MaxValue, } }; if (baseAddress.Scheme == Uri.UriSchemeHttps) { binding.Security.Mode = BasicHttpSecurityMode.Transport; } else if (baseAddress.Scheme == Uri.UriSchemeHttp) { binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; } else if ((oneAuthScheme != AuthenticationSchemes.None) && (oneAuthScheme != AuthenticationSchemes.Anonymous)) { binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; } else { binding.Security.Mode = BasicHttpSecurityMode.None; } binding.Security.Transport.ClientCredentialType = ServiceUtility.ClientCredentialTypeFromAuthenticationScheme(oneAuthScheme); AddServiceEndpoint(contractType, binding, baseAddress); if ((Description.ServiceType != null) && Attribute.IsDefined(Description.ServiceType, typeof(BinaryEndpointBehaviorAttribute), true)) { var binaryEndpointBehaviorAttribute = Attribute.GetCustomAttribute(Description.ServiceType, typeof(BinaryEndpointBehaviorAttribute), true) as BinaryEndpointBehaviorAttribute; if (binaryEndpointBehaviorAttribute != null) { var binaryBinding = new NetTcpBinding { ReceiveTimeout = TimeSpan.FromHours(1), SendTimeout = TimeSpan.FromHours(1), OpenTimeout = TimeSpan.FromHours(1), CloseTimeout = TimeSpan.FromHours(1), MaxReceivedMessageSize = int.MaxValue, }; binaryBinding.Security.Mode = SecurityMode.Transport; binaryBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; var builder = new UriBuilder(baseAddress.ToString()) { Scheme = "net.tcp", Port = binaryEndpointBehaviorAttribute.PortNumber }; AddServiceEndpoint(contractType, binaryBinding, builder.Uri); } } //Add a MEX endpoint if the attribute is defined on the service type. if ((Description.ServiceType != null) && Attribute.IsDefined(Description.ServiceType, typeof(BasicHttpBindingServiceMetadataExchangeEndpointAttribute), true)) { ServiceUtility.EnableMetadataExchange(this, baseAddress, oneAuthScheme, true); } } }
private void CreateEndpoints() { Type contractType = ServiceUtility.GetContractType(ImplementedContracts); AuthenticationSchemes oneAuthScheme; ClientRequestServiceBehaviorAttribute.GetAllAuthenticationSchemes(out oneAuthScheme); foreach (Uri baseAddress in this.m_baseAddresses) { BasicHttpContextBinding binding = new BasicHttpContextBinding { AllowCookies = true, ReceiveTimeout = TimeSpan.FromHours(1), SendTimeout = TimeSpan.FromHours(1), OpenTimeout = TimeSpan.FromHours(1), CloseTimeout = TimeSpan.FromHours(1), MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas { MaxArrayLength = int.MaxValue, MaxBytesPerRead = 2048, MaxDepth = int.MaxValue, MaxNameTableCharCount = int.MaxValue, MaxStringContentLength = int.MaxValue, } }; if (baseAddress.Scheme == Uri.UriSchemeHttps) { binding.Security.Mode = BasicHttpSecurityMode.Transport; } else if (baseAddress.Scheme == Uri.UriSchemeHttp) { binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; } else if ((oneAuthScheme != AuthenticationSchemes.None) && (oneAuthScheme != AuthenticationSchemes.Anonymous)) { binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; } else { binding.Security.Mode = BasicHttpSecurityMode.None; } binding.Security.Transport.ClientCredentialType = ServiceUtility.ClientCredentialTypeFromAuthenticationScheme(oneAuthScheme); this.AddServiceEndpoint(contractType, binding, baseAddress); ServiceUtility.EnableMetadataExchange(this, baseAddress, oneAuthScheme, true); //TODO: Add a REST endpoint (Workflow instantiated/consumed by a REST based client = AWESOME!) //The following is a start -- but the problem is that the custom binding 1) needs to have behavior configured to be httpGet enabled, as well as the service host have webHttp //Uri restAddress = new Uri(baseAddress, "/" + baseAddress.GetComponents(UriComponents.Path, UriFormat.Unescaped) + "/rest"); //ContextBindingElement context = new ContextBindingElement(); //context.ContextExchangeMechanism = ContextExchangeMechanism.HttpCookie; //context.ProtectionLevel = System.Net.Security.ProtectionLevel.None; //WebMessageEncodingBindingElement webMessageEncoding = new WebMessageEncodingBindingElement(); //HttpTransportBindingElement httpTransport; //if (baseAddress.Scheme == Uri.UriSchemeHttp) //{ // httpTransport = new HttpTransportBindingElement(); //} //else //{ // httpTransport = new HttpsTransportBindingElement(); //} //httpTransport.AuthenticationScheme = oneAuthScheme; //BindingElementCollection elements = new BindingElementCollection(); //elements.Add(context); //elements.Add(webMessageEncoding); //elements.Add(httpTransport); //CustomBinding restEndpointBinding = new CustomBinding(elements); //this.AddServiceEndpoint(contractType, restEndpointBinding, restAddress); } }
private void CreateEndpoints() { AuthenticationSchemes oneAuthScheme; ClientRequestServiceBehaviorAttribute.GetAllAuthenticationSchemes(out oneAuthScheme); foreach (var baseAddress in this.m_baseAddresses) { var binding = new WebHttpBinding { AllowCookies = true, ReceiveTimeout = TimeSpan.FromHours(1), SendTimeout = TimeSpan.FromHours(1), OpenTimeout = TimeSpan.FromHours(1), CloseTimeout = TimeSpan.FromHours(1), MaxReceivedMessageSize = int.MaxValue, TransferMode = TransferMode.Streamed, ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas { MaxArrayLength = int.MaxValue, MaxBytesPerRead = 2048, MaxDepth = int.MaxValue, MaxNameTableCharCount = int.MaxValue, MaxStringContentLength = int.MaxValue, } }; if (object.ReferenceEquals(baseAddress.Scheme, Uri.UriSchemeHttps)) { binding.Security.Mode = WebHttpSecurityMode.Transport; } else if (object.ReferenceEquals(baseAddress.Scheme, Uri.UriSchemeHttp)) { binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly; } else if ((oneAuthScheme != AuthenticationSchemes.None) && (oneAuthScheme != AuthenticationSchemes.Anonymous)) { binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly; } else { binding.Security.Mode = WebHttpSecurityMode.None; } binding.Security.Transport.ClientCredentialType = ServiceUtility.ClientCredentialTypeFromAuthenticationScheme(oneAuthScheme); //Set the content type mapper on the binding to return raw elements (for json.) var cb = new CustomBinding(binding); var webMebe = cb.Elements.Find <WebMessageEncodingBindingElement>(); var rawMapper = new RawMapper(); if (this.Description.Behaviors.Find <RawJsonRequestBehaviorAttribute>() != null) { rawMapper.UseRawForJson = true; } webMebe.ContentTypeMapper = rawMapper; Type contractType = ServiceUtility.GetContractType(ImplementedContracts); AddServiceEndpoint(contractType, cb, baseAddress); } }