Increasing WCF Performance - performance

We have design AJAX – Enable WCF web services for our mobile application. Web service methods returns data in JSON format. We are observing delay in calling web services and binding it to mobile widget. The size of data in approximately 50K.
According to Code Project , we have applied changes to web.config file of WCF Web Service.
Similarly, following one of the stackoverflow question we are trying to increase message size. Now, problem is how we should apply changes to our current web.config file so that message size is increase. We are using default NET 4.0 setting. Also, do we need to define end point on our client web.config file. Can someone provide client side web.config?
Our current server web.config settings is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<identity impersonate="false" />
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.serviceModel>
<diagnostics performanceCounters="All"></diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<!--Increase WCF Performance-->
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<!--Increase WCF Performance-->
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000"/>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileWCFService.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileWCFService.Service1" behaviorConfiguration="MobileService.webHttpBehavior" />
</service>
</services>
</system.serviceModel>
</configuration>

Can anyone confirm if changes I applied is valid or not and mark it has confirm answers?
<system.serviceModel>
<diagnostics performanceCounters="All"></diagnostics>
<behaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<!--Increase WCF Performance-->
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!--Increase WCF Performance-->
<bindings>
<webHttpBinding>
<binding name="webHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000"/>
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileWCFService.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileWCFService.Service1" behaviorConfiguration="MobileService.webHttpBehavior" bindingConfiguration="webHttp" />
</service>
</services>

Related

Publishing a WCF service using visual studio 2013, cannot find service afterwards

I am trying to develope a silverlight page which uses a WCF service to communicate to my database (external database on a webhotel). It all works fine locally, but when I deploy the page and run it, I get the error "The remote server returned an error: NotFound".
<system.serviceModel>
<bindings>
<customBinding>
<binding name="FundFinder.Web.FundSilverlightService.customBinding0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<services>
<service name="FundFinder.Web.FundSilverlightService">
<endpoint address="http://subdomain.domain.com" binding="customBinding" bindingConfiguration="FundFinder.Web.FundSilverlightService.customBinding0"
contract="FundFinder.Web.FundSilverlightService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
I am not sure if I have configured the service correctly, the above is simply that which Visual Studio gave me when I added the service to the solution.
This is a generic error. Please turn on debug in web.config and turn the exception details
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors> ## Heading ##
</behaviors>
see what exception its throwing.

WCF Service, the type provided as the service attribute values...could not be found

I have this issue a long time ago and just cannot recall how to resolve it or perphaps its something new. I created a WCF service which I will later use in web application that calls the WCF service amongst others from a remote location. Right now I am trying to host in IIS and even tried the WCFTestClient. The error I get when I try to browse to the service; is the following:
The type MyService.Service1 provided as the Service attribute
value in the ServiceHost directive, or provided in the
configuration element system.serviceModel/serviceHostingEnvironment/
serviceActivations could not be found.
I figured its probably my web.config file but I cannot see whats wrong:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" crossDomainScriptAccessEnabled="false" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="webHttpBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="webHttpBehavior" name="WcfInstanceRules2.Service1">
<endpoint address=""
binding="webHttpBinding"
contract="WcfRules2.IServiceS" behaviorConfiguration="web"/>
<endpoint address="mex"
binding="webHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
I would like this to be eventually a rest service delivering data in json format.
Check your .svc file and see what service it's referencing - probably MyService.Service1, which doesn't exist in your config. It looks like it should be referencing WcfInstanceRules2.Service1.

how to configure HTTPS and HTTP binding for Ajax Enabled WCF web service

I encountered an errror during the accessing of my web service in https site.
i think this is a configuration error because its looking for an https binding.
here is the web.config of the web service:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="WebService.ListViewWebService" behaviorConfiguration="WebService.ListViewWebServiceBehavior">
<endpoint address=""
behaviorConfiguration="WebService.ListViewWebServiceAjaxBehavior"
binding="webHttpBinding"
contract="WebService.IListViewWebService"/>
<endpoint address="https://win-d741qhlbivf:13241/services/DPT/_vti_bin/DPT.WebService/ListViewWebService.svc"
behaviorConfiguration="WebService.ListViewWebServiceAjaxBehavior1"
binding="webHttpsBinding"
contract="WebService.IListViewWebService2"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="webHttpBinding">
<security mode="None" />
</binding>
<binding name="webHttpsBinding">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WebService.ListViewWebServiceAjaxBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WebService.ListViewWebServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
thanks for the help in advance.
Also, I am not sure if this has something to do with the issue but the web application hosted in a cloud environment...do i need a special configuration for that?...
thanks again..
One of my tutorials will help you:
http://netpl.blogspot.com/2010/05/how-to-programmatically-configure-ssl.html
The tutorial starts with the declarative configuration and then shows how to create binding/endpoints programatically.
This config will respond to requests in HTTP and HTTPS , note that the ports are different and have to match what the host is expecting (in this case it happens to be iis)
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" />
<services>
<service name="KPIGetter_Library.KPIGetter">
<endpoint address=""
behaviorConfiguration="restfulBehaviour"
binding="webHttpBinding"
bindingConfiguration="webHttpBindingWithJsonP"
contract="KPIGetter_Library.IKpiGetter" />
<endpoint address=""
behaviorConfiguration="restfulBehaviour"
binding="webHttpBinding"
bindingConfiguration="webHttpsBindingWithJsonP"
contract="KPIGetter_Library.IKpiGetter" />
<host>
<baseAddresses>
<add baseAddress="http://hodbd05:8000/kpigetter" />
<add baseAddress="https://hodbd05:8001/kpigetter" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true">
<security mode="None" />
</binding>
<binding name="webHttpsBindingWithJsonP" crossDomainScriptAccessEnabled="true">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
An important issue is that you should use webHttpBinding and not the basicHttpBinding for ajax-enabled WCF services.
A simple working example is found here: Scott's blog on asp.net

Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https]

I have tried Google and also other posts on SO, nothing I have tried has resolved my issue so far.
I thought this was going to be the answer. No dice.
I also read through most of the posts here on SO that mentioned the same error message I'm receiving, like this.
My site is secure, https. I have 3 WCF services that handle my async ajax stuff running on this site. When I attempt to access any of those services I receive this error:
Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https].
My config:
<behaviors>
<endpointBehaviors>
<behavior name="ajaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ajaxAsynchBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="MyApp.Web.Services.CascadingList">
<endpoint address="" behaviorConfiguration="ajaxAsynchBehavior"
binding="webHttpBinding" bindingConfiguration="webBinding" contract="MyApp.Web.Services.CascadingList" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://[domain]/MyApp/Services/CascadingList.svc" />
</baseAddresses>
</host>
</service>
<service name="MyApp.Web.Services.AutoComplete">
<endpoint address="" behaviorConfiguration="ajaxAsynchBehavior"
binding="webHttpBinding" bindingConfiguration="webBinding" contract="MyApp.Web.Services.AutoComplete" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://[domain]/MyApp/Services/AutoComplete.svc" />
</baseAddresses>
</host>
</service>
<service name="MyApp.Web.Services.Validation">
<endpoint address="" behaviorConfiguration="ajaxAsynchBehavior"
binding="webHttpBinding" bindingConfiguration="webBinding" contract="MyApp.Web.Services.Validation" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://[domain]/MyApp/Services/Validation.svc" />
</baseAddresses>
</host>
</service>
</services>
I should be able to go to "https://[domain]/MyApp/SubmitNew.aspx" and the cascading lists should work.
Currently the "parent" list shows "[Method 500]" and the child lists remain disabled.
When I hit the "SubmitNew" page, my server's event log shows "Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/51442863 Exception: System.ServiceModel.ServiceActivationException: The service '/MyApp/Services/CascadingList.svc' cannot be activated due to an exception during compilation. The exception message is: Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https]."
If I navigate directly to "https://[domain]/MyApp/Services/CascadingList.svc" I also receive the aforementioned error.
UPDATES
This happens on our production server. Secure site w/ SSL cert was set up long before I joined the company. I just added a new virtual directory under the secure site for my new web app.
In IIS:
Secure Web Applications (has SSL cert)
MyApp
WebApp1
WebApp2
I fixed my config (above) to use the correct behaviorConfiguration.
-- 2012.04.24 13:15 CDT --
When I changed my config to this (below) I received this error: "System.ServiceModel.ServiceActivationException: The service '/MyApp/Services/CascadingList.svc' cannot be activated due to an exception during compilation. The exception message is: There is no endpoint behavior named 'ajaxAsynchBehavior'"
<serviceBehaviors>
<behavior name="ajaxAsynchBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<services>
<service name="MyApp.Web.Services.CascadingList">
<endpoint address="" behaviorConfiguration="ajaxAsynchBehavior"
binding="basicHttpBinding" bindingConfiguration="ajaxBinding" contract="MyApp.Web.Services.CascadingList" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://[domain]/MyApp/Services/CascadingList.svc" />
</baseAddresses>
</host>
</service>
.
.
.
</services>
So I changed it back to:
<behaviors>
<endpointBehaviors>
<behavior name="ajaxBehavior">
<enableWebScript />
</behavior>
<behavior name="clientBehavior" />
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ajaxAsynchBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyApp.Web.Services.CascadingList">
<endpoint address="" behaviorConfiguration="ajaxBehavior"
binding="basicHttpBinding" bindingConfiguration="ajaxBinding" contract="MyApp.Web.Services.CascadingList" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://[domain]/MyApp/Services/CascadingList.svc" />
</baseAddresses>
</host>
</service>
.
.
.
</services>
Your configuration looks fine, except for the service behaviors which will not be attached as you did not add thebehaviorConfiguration with proper name in the <service> tags. But this is not causing your error.
Are you by any chance using the Visual Studio built-in web server (Cassini)? Because it looks like you do and please keep in mind that it does not support HTTPS. This is probably why you are getting the error. Try deploying your site to local IIS server and check if it works then. You can see how to set up a https development web site on IIS 7 here. One more thing, once you deploy the site to IIS keep in mind that the baseAddress tags will be ignored but your services will be accessible by their original names ie CascadingList.svc (unless configured differently).
I will be giving credit to dmusial for the answer (including all the comments), but I wanted to post my final config changes just in case this benefits someone else.
This post also helped me arrive at a solution.
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webScriptEnablingBehavior">
<enableWebScript />
</behavior>
<behavior name="clientBehavior" />
</endpointBehaviors>
<serviceBehaviors>
<behavior name="webScriptEnablingBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
<wsHttpBinding>
<binding name="customBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="1048576" maxReceivedMessageSize="1048576"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true" />
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="None" negotiateServiceCredential="false" establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="MyApp.Web.Services.CascadingList" behaviorConfiguration="webScriptEnablingBehavior">
<endpoint address="" behaviorConfiguration="webScriptEnablingBehavior"
binding="webHttpBinding" bindingConfiguration="webBinding" contract="MyApp.Web.Services.CascadingList" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
<service name="MyApp.Web.Services.AutoComplete" behaviorConfiguration="webScriptEnablingBehavior">
<endpoint address="" behaviorConfiguration="webScriptEnablingBehavior"
binding="webHttpBinding" bindingConfiguration="webBinding" contract="MyApp.Web.Services.AutoComplete" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
<service name="MyApp.Web.Services.Validation" behaviorConfiguration="webScriptEnablingBehavior">
<endpoint address="" behaviorConfiguration="webScriptEnablingBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="MyApp.Web.Services.Validation" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
I solved my case with this configuration:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<security mode="Transport">
</security>
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add binding="webHttpBinding" bindingConfiguration="webBinding" scheme="https" />
</protocolMapping>
</system.serviceModel>

WCF service under https environment

I've created and tested WCF service, everything works fine.
When I deployed to TEST environment and tried to open https://my.site/myapp/EnrollmentService.svc I've got the error message:
Could not find a base address that
matches scheme http for the endpoint
with binding
MetadataExchangeHttpBinding.
Registered base address schemes are
[https].
Internet showed me that I need to add some more configuration options:
http://www.codeproject.com/KB/WCF/7stepsWCF.aspx
I've added some settings to service web.config file. Now it looks like in the following way:
<system.serviceModel>
<services>
<service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
<endpoint
address="https://my.site/myapp/EnrollmentService.svc"
binding="basicHttpBinding"
bindingConfiguration="TransportSecurity"
contract="McActivationApp.IEnrollmentService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.IEnrollmentService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="McActivationApp.EnrollmentServicBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
Actually, I've added "bindings" section and specified it for my endpoint.
But this changed nothing...
Please advise, what I need to do. Thanks a lot!
P.S. Are there any differences in WCF service consuming from https and http resources?
When you want to expose your service only over HTTPS (site does not support HTTP at all) you can't use anything that is dependent on HTTP. Your current configuration exposes help page on HTTP and also mex endpoing (with wrong contract) on HTTP. So try this:
<system.serviceModel>
<services>
<service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" contract="McActivationApp.IEnrollmentService"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="McActivationApp.EnrollmentServicBehavior">
<serviceMetadata httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
You have got http metadata endpoint that should be changed to https as below.
<serviceMetadata httpsGetEnabled="True"/>
Also if not necessary you should remove the mex and https metadata endpoint from production as a best practice.
To fix the problem by allowing HTTP, you need to add a http binding in IIS:
Navigate to your site in IIS
Click 'Bindings...' in the Actions panel on the right.
Click 'Add'
Select 'http' and OK out.
Alternatively, you can prevent the problem by either deleting the line, or changing:
<serviceMetadata httpGetEnabled="True"/>
to:
<serviceMetadata httpsGetEnabled="True"/>

Resources