Get Windows username via WCF Data Services (Silverlight) - windows

I'm trying get the windows username for my silverlight 4 application using WCF Data Services. I'm seeing the username when I'm debugging the application from my local machine. But when I'm running the application from web server, the username is coming out as null.
Please let me know if you need any other details. Any help is greatly appreciated.
Here is the method I'm using to get the username :
[OperationContract]
public string GetWindowsUsername()
{
string usr = HttpContext.Current.User.Identity.Name;
return usr.ToString();
}
Here is my Web.Config :
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2147483647" />
<authentication mode="Windows" />
<!--<anonymousIdentification enabled="true"/>-->
<authorization>
<allow users="*"/>
</authorization>
<!--<identity impersonate="false" />-->
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="OrderTrackingSystem.Web.OTSService.customBinding0"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security>
<transport clientCredentialType="Ntlm" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="OrderTrackingSystem.Web.OTSService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="OrderTrackingSystem.Web.OTSService.customBinding0"
name="OTSServiceCustom" contract="OrderTrackingSystem.Web.OTSService" />
</service>
</services>
</system.serviceModel>
Here is my Service Config :
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="OTSServiceCustom" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49458/OTSService.svc" binding="basicHttpBinding"
bindingConfiguration="OTSServiceCustom" contract="OTSProxy.OTSService"
name="OTSServiceCustom" />
</client>
</system.serviceModel>
</configuration>

I tried to create a demo app to test things, the following worked for me..
[OperationContract]
public string GetWindowsUsername()
{
string usr = ServiceSecurityContext.Current.WindowsIdentity.Name;
return usr;
}
But inorder to make this work you have to configure your binding as:
<bindings>
<basicHttpBinding>
<binding name="OTSServiceCustom">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
Hope this helps...

Related

Will IIS hosted web service take more time to respond than self hosted service?

I have microservices, all are deployed in IIS. When I trigger request to those services taking 2k+ millisecond for each and every request. But, If I run those services using IIS Express and self hosted way(for wcf) I got response in 100 millisecond. Verified time using Postman.
Already tried some basic verification like ,
App Pool recycling (1740 minutes)
StartMode(Always Running)
PreEnabled(True)
AppInitialization also set.
Can anyone suggest solution for this problem?
WCF implementation here,
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
<system.serviceModel>
<services>
<service name="CalculationService">
<endpoint address="rest" behaviorConfiguration="CalculationServiceAspNetAjaxBehavior" bindingConfiguration="webHttpBinding_IMyService" binding="webHttpBinding" contract="ICalculationService" />
<endpoint address="" binding="basicHttpBinding" contract="ICalculationService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://ip/CalculationService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpBinding_IMyService" maxBufferPoolSize="524288000" maxBufferSize="524288000" maxReceivedMessageSize="524288000">
<readerQuotas maxDepth="524288000" maxStringContentLength="524288000" maxArrayLength="524288000" maxBytesPerRead="524288000" maxNameTableCharCount="524288000" />
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="CalculationService.CalculationServiceAspNetAjaxBehavior">
<webHttp defaultOutgoingResponseFormat="Json" helpEnabled="true" faultExceptionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="http" />
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

sharepoint 2013 wcf service The HTTP request is unauthorized

I'm using wcf service hosted on iis7 over https and when i call service in windows 8 app it returns error
"The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'."
this service web.config
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="CellStorageServiceBehavior" name="Microsoft.SharePoint.SoapServer.CellStorages">
<endpoint address="CellStorageService" binding="basicHttpBinding"
bindingConfiguration="StreamBinding" contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
<endpoint address="CellStorageServiceBasic" binding="basicHttpBinding"
bindingConfiguration="StreamBindingBasic" contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
<endpoint address="CellStorageServiceDigest" binding="basicHttpBinding"
bindingConfiguration="StreamBindingDigest" contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
<endpoint address="CellStorageServiceNtlm" binding="basicHttpBinding"
bindingConfiguration="StreamBindingNtlm" contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
</service>
<service behaviorConfiguration="CellStorageServiceHttpsBehavior" name="Microsoft.SharePoint.SoapServer.CellStoragesHttps">
<endpoint address="CellStorageService" binding="basicHttpBinding"
bindingConfiguration="StreamBindingHttps" contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
<endpoint address="CellStorageServiceBasic" binding="basicHttpBinding"
bindingConfiguration="StreamBindingHttpsBasic" contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
<endpoint address="CellStorageServiceDigest" binding="basicHttpBinding"
bindingConfiguration="StreamBindingHttpsDigest" contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
<endpoint address="CellStorageServiceNtlm" binding="basicHttpBinding"
bindingConfiguration="StreamBindingHttpsNtlm" contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
</service>
<service behaviorConfiguration="ClaimProviderWebServiceBehavior" name="Microsoft.SharePoint.SoapServer.SPClaimProviderWebService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="TextStreamBindingNoSecurity"
bindingNamespace="http://schemas.microsoft.com/sharepoint/claims/"
behaviorConfiguration="HttpBinding.LargeDataEndpointBehavior"
contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
</service>
<service behaviorConfiguration="HttpsClaimProviderWebServiceBehavior" name="Microsoft.SharePoint.SoapServer.SPClaimProviderWebServiceHttps">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="TextStreamBindingHttpsNoSecurity"
bindingNamespace="http://schemas.microsoft.com/sharepoint/claims/"
behaviorConfiguration="HttpBinding.LargeDataEndpointBehavior"
contract="MOL.Service.ISAPI.MOL.IServiceHosted" />
</service>
</services>
<protocolMapping>
<add scheme="https" binding="webHttpBinding" bindingConfiguration="StreamBindingHttps" />
<add scheme="http" binding="webHttpBinding" bindingConfiguration="StreamBinding" />
</protocolMapping>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP"
crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
<basicHttpBinding>
<binding name="StreamBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
transferMode="StreamedResponse">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
<binding name="StreamBindingBasic" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
transferMode="StreamedResponse">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
<binding name="StreamBindingDigest" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
transferMode="StreamedResponse">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Digest"/>
</security>
</binding>
<binding name="StreamBindingNtlm" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
transferMode="StreamedResponse">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="TextStreamBindingNoSecurity" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Text"
transferMode="StreamedResponse">
</binding>
<binding name="StreamBindingHttps" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
transferMode="StreamedResponse">
<security mode="Transport">
<transport clientCredentialType="Windows"/>
</security>
</binding>
<binding name="StreamBindingHttpsBasic" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
transferMode="StreamedResponse">
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
</binding>
<binding name="StreamBindingHttpsDigest" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
transferMode="StreamedResponse">
<security mode="Transport">
<transport clientCredentialType="Digest"/>
</security>
</binding>
<binding name="StreamBindingHttpsNtlm" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Mtom"
transferMode="StreamedResponse">
<security mode="Transport">
<transport clientCredentialType="Ntlm"/>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="TextStreamBindingHttpsNoSecurity" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true"
maxBufferSize="4194304" maxReceivedMessageSize="4194304" messageEncoding="Text"
transferMode="StreamedResponse">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
<binding name="mexHttpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="Windows"/>
</security>
</binding>
<binding name="mexNtlmHttpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
<behaviors>
<serviceBehaviors>
<behavior name="CellStorageServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="CellStorageServiceHttpsBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="ClaimProviderWebServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="HttpsClaimProviderWebServiceBehavior" >
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="HttpBinding.LargeDataEndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
and this way to call service from windows 8 app
private async void ConfigureHttpsProxy()
{
try
{
SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
httpsTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Ntlm;
CustomBinding binding = new CustomBinding(securityElement, httpsTransport);
binding.Name = "StreamBindingHttps";
EndpointAddress remoteAddress = new EndpointAddress(addressHttps);
var client = new ServiceHosted.ServiceHostedClient(binding, remoteAddress);
client.ClientCredentials.UserName.UserName = "UserName";
client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
var result = await client.GetUserAsync("ahmed", "123456");
var x = result.DepartmentName;
}
catch { }
}
after weeks of search result was as below:
NTLM solution steps:
1- From center admin:
Center administration:
NT Authority\local -> full control
current user -> full control
Authentication Provider
claims Based Authentication -> Default
Enable anonymous access
Enable windows -> Kerberos
2- From web config:
Add the following node to the service’s serviceBehaviors behavior node.
3- From client side:
_serviceClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password");
_serviceClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
4- From service side:
Enable impersonation at the web site. Either enable ASP.NET impersonation for the entire site or temporarily impersonate the user from within the web site by using WindowsIdentity.Impersonate(token).
Add the following attribute to each method in the WCF service that needs impersonation.
[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
for more details back to links :
http://blogs.msdn.com/b/knowledgecast/archive/2007/01/31/the-double-hop-problem.aspx
http://blogs.msdn.com/b/securitytools/archive/2009/11/04/double-hop-windows-authentication-with-iis-hosted-wcf-service.aspx

WCF Web Service - Custom Binding (binary encoding) is slower than basicHttpBinding

I have an ASP.Net MVC application which gets it's data from WCF Web Services. They both hosted on the same server and on IIS 7.5
Recently, my MVC application started to get increased hits and needed some optimization. Google insight results showed server response times could be a problem so I decided to start with optimizing WCF services first. (as the mvc application does not work with the database directly but uses WCF services to get data)
Since I can not implement these changes on the live application, I created a PTR version of both the MVC application and WCF services.
The live web service uses basicHttpBinding and in PTR version I switched over to the customBinding with binaryMessageEncoding, however, two Google insight reports for two seperate applications showed that Live version is actually faster than the PTR version.
I don't quite understand what's going on with the results. Is there something that I'm doing wrong or is it expected to binaryMessageEncoding slower than basicHttpBinding's text/xml encoder?
I'm using .Net Framework 4.5 and my services are working on database tables that contains roughly 2 - 10K records per table.
Google insight results are: 2.1 seconds server response for the live application, 4 seconds for the PTR version.
I also have caching and compression enabled on IIS.
These are the web.config files for Live application:
Live WCF Web Server web.config
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="True" aspNetCompatibilityEnabled="True" />
<behaviors>
<serviceBehaviors>
<behavior name="Development">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
<serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="800" maxConcurrentInstances="400" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="KPHttpBinding"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
closeTimeout="01:50:00"
openTimeout="01:50:00"
sendTimeout="01:50:00"
receiveTimeout="01:50:00">
<readerQuotas maxDepth="128"
maxStringContentLength="2147483647"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<diagnostics performanceCounters="All" />
<services>
<service name="KP.ServiceLib.NewsService" behaviorConfiguration="Development">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="KPHttpBinding" contract="KP.ServiceLib.Interfaces.INewsService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="KP.ServiceLib.UserService" behaviorConfiguration="Development">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="KPHttpBinding" contract="KP.ServiceLib.Interfaces.IUserService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="KP.ServiceLib.BlogService" behaviorConfiguration="Development">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="KPHttpBinding" contract="KP.ServiceLib.Interfaces.IBlogService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="KP.ServiceLib.ContentService" behaviorConfiguration="Development">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="KPHttpBinding" contract="KP.ServiceLib.Interfaces.IContentService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="KP.ServiceLib.MediaService" behaviorConfiguration="Development">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="KPHttpBinding" contract="KP.ServiceLib.Interfaces.IMediaService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Live MVC Application web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="KPHttpBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://mydomain.com/BlogService.svc" binding="basicHttpBinding" behaviorConfiguration="ServiceBehaviour" bindingConfiguration="KPHttpBinding" contract="KPBlogService.IBlogService" name="BasicHttpBinding_IBlogService" />
<endpoint address="http://mydomain.com/ContentService.svc" binding="basicHttpBinding" behaviorConfiguration="ServiceBehaviour" bindingConfiguration="KPHttpBinding" contract="KPContentService.IContentService" name="BasicHttpBinding_IContentService" />
<endpoint address="http://mydomain.com/NewsService.svc" binding="basicHttpBinding" behaviorConfiguration="ServiceBehaviour" bindingConfiguration="KPHttpBinding" contract="KPNewsService.INewsService" name="BasicHttpBinding_INewsService" />
<endpoint address="http://mydomain.com/UserService.svc" binding="basicHttpBinding" behaviorConfiguration="ServiceBehaviour" bindingConfiguration="KPHttpBinding" contract="KPUserService.IUserService" name="BasicHttpBinding_IUserService" />
<endpoint address="http://mydomain.com/MediaService.svc" binding="basicHttpBinding" behaviorConfiguration="ServiceBehaviour" bindingConfiguration="KPHttpBinding" contract="KPMediaService.IMediaService" name="BasicHttpBinding_IMediaService" />
</client>
</system.serviceModel>
PTR WCF Web Service web.config
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="True" aspNetCompatibilityEnabled="True" />
<behaviors>
<serviceBehaviors>
<behavior name="Production">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483646" />
<serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="100" maxConcurrentInstances="100" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="BinaryHttpBinding">
<reliableSession />
<binaryMessageEncoding compressionFormat="GZip" maxSessionSize="2147483647" />
<httpTransport maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<services>
<service name="KP.ServiceLib.NewsService" behaviorConfiguration="Production">
<endpoint address="" binding="customBinding" bindingConfiguration="BinaryHttpBinding" contract="KP.ServiceLib.Interfaces.INewsService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="KP.ServiceLib.UserService" behaviorConfiguration="Production">
<endpoint address="" binding="customBinding" bindingConfiguration="BinaryHttpBinding" contract="KP.ServiceLib.Interfaces.IUserService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="KP.ServiceLib.BlogService" behaviorConfiguration="Production">
<endpoint address="" binding="customBinding" bindingConfiguration="BinaryHttpBinding" contract="KP.ServiceLib.Interfaces.IBlogService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="KP.ServiceLib.ContentService" behaviorConfiguration="Production">
<endpoint address="" binding="customBinding" bindingConfiguration="BinaryHttpBinding" contract="KP.ServiceLib.Interfaces.IContentService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="KP.ServiceLib.MediaService" behaviorConfiguration="Production">
<endpoint address="" binding="customBinding" bindingConfiguration="BinaryHttpBinding" contract="KP.ServiceLib.Interfaces.IMediaService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
PTR MVC Application web.config
<system.serviceModel>
<bindings>
<customBinding>
<binding name="BinaryHttpBinding">
<reliableSession />
<binaryMessageEncoding compressionFormat="GZip" maxSessionSize="2147483647" />
<httpTransport maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="Production">
<dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="66560" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://mydomain.com/ptr/NewsService.svc"
binding="customBinding" bindingConfiguration="BinaryHttpBinding"
contract="KPNewsService.INewsService" name="BasicHttpBinding_INewsService" behaviorConfiguration="Production" />
<endpoint address="http://mydomain.com/ptr/BlogService.svc"
binding="customBinding" bindingConfiguration="BinaryHttpBinding"
contract="KPBlogService.IBlogService" name="BasicHttpBinding_IBlogService" behaviorConfiguration="Production" />
<endpoint address="http://mydomain.com/ptr/ContentService.svc"
binding="customBinding" bindingConfiguration="BinaryHttpBinding"
contract="KPContentService.IContentService" name="BasicHttpBinding_IContentService" behaviorConfiguration="Production" />
<endpoint address="http://mydomain.com/ptr/MediaService.svc"
binding="customBinding" bindingConfiguration="BinaryHttpBinding"
contract="KPMediaService.IMediaService" name="BasicHttpBinding_IMediaService" behaviorConfiguration="Production" />
<endpoint address="http://mydomain.com/ptr/UserService.svc"
binding="customBinding" bindingConfiguration="BinaryHttpBinding"
contract="KPUserService.IUserService" name="BasicHttpBinding_IUserService" behaviorConfiguration="Production" />
</client>
</system.serviceModel>

How do you enable SSL for WCF webHttpBinding AJAX Ajax Enabled Service?

I have a WCF webHttpBinding AJAX Enabled Service that I need to configure for SSL. SSL is turned on at the server. I know how to do this for basicHttpBinding but don't for webHttpBinding. My config is:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AlphaFrontEndSiteASP.TestsServiceAspNetAjaxBehavior">
<enableWebScript />
<webHttp />
</behavior>
<behavior name="AlphaFrontEndSiteASP.Services.TestsService">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="AlphaFrontEndSiteASP.Services.TestsService" behaviorConfiguration="MetadataBehavior">
<endpoint address="" behaviorConfiguration="AlphaFrontEndSiteASP.TestsServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="AlphaFrontEndSiteASP.Services.TestsService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
</system.serviceModel>
</configuration>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>

Need Help With AJAX-Enabled WCF Services (Please Look # System.ServiceModel in Web.Config)

I have been having some problems with this for a few days now...
I have designed a WCF Class Library - WebAPILibrary. It is under my
solution which also contains my web project.
I now am attempting to enable a AJAX/JSON response to a search query.
In the client code examples, I see something to the effect:
function btnsrch_onclick() {
var query = document.getElementById('q');
var type = document.getElementById('type');
$(document).ready(function(){
$.getJSON("http://api.domain.com/services/trade.svc?q=" + query.value + "&type=" + type.value + "&format=json",
function(data){
$.each(data.items, function(i,item){
$("<img/>").attr("src", item.media.m).appendTo("#images");
if ( i == 3 ) return false;
});
});
});
}
MY PROBLEM IS that, up until this point, I have been happily referencing my WCF class library in my Web Project. But, now it seems I need to create a SVC file and use it to
execute my javascript AJAX/JSON calls.
MY QUESTION IS:
1) How do I create the SVC file in cooperation with my WCF class library?
2) I am not quite sure what I need to put under system.ServiceModel for my web project's
web.config. Could some kind soul kindly look at what I currently have and advise me on
what I need to be doing?
WEB PROJECT SYSTEM.SERVICEMODEL (WEB.CONFIG):
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ITradeService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
<binding name="WSHttpBinding_IAuthService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
<binding name="WSHttpBinding_IAuthService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
<binding name="WSHttpBinding_ITradeService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8731/Design_Time_Addresses/Trade/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITradeService"
contract="ITradeService" name="WSHttpBinding_ITradeService">
<identity>
<dns value="localhost:8731" />
</identity>
</endpoint>
<endpoint address="http://localhost:8731/Design_Time_Addresses/Authentication/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAuthService"
contract="IAuthService" name="WSHttpBinding_IAuthService">
<identity>
<dns value="localhost:8731" />
</identity>
</endpoint>
<endpoint address="http://localhost:8731/Design_Time_Addresses/Authentication/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAuthService1"
contract="Trezoro.WebAPI.Authentication.IAuthService" name="WSHttpBinding_IAuthService1">
<identity>
<dns value="localhost:8731" />
</identity>
</endpoint>
<endpoint address="http://localhost:8731/Design_Time_Addresses/Trade/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITradeService1"
contract="Trezoro.WebAPI.Trade.ITradeService" name="WSHttpBinding_ITradeService1">
<identity>
<dns value="localhost:8731" />
</identity>
</endpoint>
</client>
</system.serviceModel>
WCF CLASS LIBRARY SYSTEM.SERVICEMODEL (APP.CONFIG):
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="WebAPILibrary.WebAPIBehavior"
name="Company.WebAPI.Trade.TradeService">
<endpoint address="" binding="wsHttpBinding" contract="Company.WebAPI.Trade.ITradeService">
<identity>
<dns value="localhost:8731" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/Trade/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="WebAPILibrary.WebAPIBehavior"
name="Company.WebAPI.Authentication.AuthService">
<endpoint address="" binding="wsHttpBinding" contract="Company.WebAPI.Authentication.IAuthService">
<identity>
<dns value="localhost:8731" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/Authentication/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WebAPILibrary.WebAPIBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WebAPILibrary.WebAPIBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
You should never reference your WCF library in any other project. It is meant to be used as a service, not as a class library.

Resources