Slowing web application with WCF on timely request - asp.net

I am new for the WCF, i have web application which uses WCF Service as a data access layer. I am using wcf service library and hosterd it on IIS7. It works fine for few initial service calls but hangs an application for further request. When i reset IIS , then again it is working fine for some time.
Below is the service configuration in web.config of web app
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IRoaster" closeTimeout="00:10:00"
openTimeout="00:01:00" receiveTimeout="00:02:00" sendTimeout="00:03:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="199999488" 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" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://asdf.com/RoasterService/RoasterService.Roaster.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IRoaster"
contract="RoasterService.IRoaster" name="WSHttpBinding_IRoaster">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
Is there if i comment all the wcf call then for dummy values application works fine. please suggest the appropriate solution

You're probably not disposing the WCF client instance at the end of the request. Look at this post for the gotcha's in working with WCF clients.

Related

WCF Rest Service with both http and https bindings

I'm trying to create a rest service that can accept both http and https traffic. The reason for this is that my company offers our customers both a hosted and non-hosted solution. In the hosted solution, all traffic goes through an F5 which strips out the SSL and forwards it to our servers in regular http.
The non-hosted solutions have their web servers handle the SSL (thus, the server is expecting https security).
The binding was originally defined like so:
<webHttpBinding>
<binding closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
</security>
</binding>
</webHttpBinding>
However, this did not work for our non-hosted customers. I then changed it to this
<webHttpBinding>
<binding closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
</security>
</binding>
</webHttpBinding>
But, as you can guess, this did not work for our hosted customers.
Is it possible to have a WCF rest service using the .NET 4.0 framework accept both http and https traffic?
I have tried this:
<webHttpBinding>
<binding name="normalRestBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
</security>
</binding>
<binding name="secureRestBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
</security>
</binding>
</webHttpBinding>
with this service definition:
<service name="theService" behaviorConfiguration="RestServiceBehavior">
<endpoint name="normalRestEndpoint" address="" behaviorConfiguration="RestEndpoint" binding="webHttpBinding" bindingConfiguration="normalRestBinding" contract="theContract">
<identity>
<dns />
</identity>
</endpoint>
<endpoint name="secureRestEndpoint" address="" behaviorConfiguration="RestEndpoint" binding="webHttpBinding" bindingConfiguration="secureRestBinding" contract="theContract">
<identity>
<dns />
</identity>
</endpoint>
</service>
Using these, I am now getting this error when trying to access the endpoint over regular http:
Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http].
Any help would be greatly appreciated.
Thanks!
Was able to figure this out.
The code I put toward the bottom of the questions was fine.
To resolve that error message, I had to ensure that an https binding existed in IIS on the server(s) I was attempting to use this web config for.
Sorry for self-answering, but I didn't want to leave this open and somebody waste their time trying to answer it for me!
Thanks!

The maximum message size quota for incoming messages (33554431) has been exceeded

My client application is calling a web service, everything works fine, except a function call always throw this error (The maximum message size quota for incoming messages (33554431) has been exceeded.)
I have tried to increase the maxBufferSize in the app.config file of my client application to 335544310, but it did not help solving this problem.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpsEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferSize="33554431" maxBufferPoolSize="33554431" maxReceivedMessageSize="33554431" messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="33554431" maxArrayLength="33554431" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://api.smartmailpro.com/2.0/API.svc" binding="basicHttpBinding" bindingConfiguration="basicHttpsEndpoint" contract="SmartMailProApi.API" name="basicHttpsEndpoint" />
</client>
</system.serviceModel>
I suspect that there are two possibilities
1) The value that I am using is too large
2) I need to perform the same update to the server web services as well
Could anyone point me to the right direction, please?
What are the real purposes of following three parameters :
maxBufferSize="33554431"
maxBufferPoolSize="33554431"
maxReceivedMessageSize="33554431"
Enlarge the value of the maxBufferSize to 2147483647, and solved the problem.

Config troubles consuming Web Service ASP.Net (Not WCF)

Well, i can't solve the following problem.
I have the next:
* A Web Service development in C# + .Net Framework 3.5 + iBatis (VS2010) with some WebMethods.
* The Web Service run on a local server, in IIS 5.1 (http://localhost/BookService/BookService.asmx).
* An application WF+C# + .Net Framework 3.5 (VS2010) where the BO layer have a service reference to the Web Service.
The app.config generated by Service Reference is:
<?xml version="1.0" encoding="utf-8" ?>ยด
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BookServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://10.0.2.15/BookService/BooksService.asmx"
binding="basicHttpBinding" bindingConfiguration="BookServiceSoap"
contract="BookService.BookServiceSoap" name="BookServiceSoap" />
</client>
</system.serviceModel>
</configuration>
I'm trying to connecting me to the web service making for example
BookService.BookServiceSoapClient query = new BookService.BookServiceSoapClient("BookServiceSoap","http://10.0.2.15/BookService/BookService.asmx");
or with out the endpointname and the url
BookService.BookServiceSoapClient query = new BookService.BookServiceSoapClient();
But in execution time appears the following message
Could not find endpoint element with name 'BookServiceSoap'
and contract 'BookService.BookServiceSoap' in the ServiceModel
client configuration section. This might be because no
configuration file was found for your application, or because
no endpoint element matching this name could be found in the client element.
Can somebody show me un right example to call for example the method HelloWorld.
Regards!

How do I configure a WCF service that calls other services behind a load balancer?

I haven't deployed behind a load balancer before. My customer has a WCF service built and tested on servers using a service model configuration that is relatively straightforward. It provides a service to return an image of a map for another application. To get the map, it calls other services.
The service was built in Visual Studio 2010 targeting the 3.5 framework. The customer is using IIS 7.5 and an F5 load balancer. When moving to the production server, the Web.config was changed to add the load balancer behavior and specify the endpoint to show the physical and logical address of the service:
<services>
<service behaviorConfiguration="Service.Service1Behavior" name="StaticMapImageService.Data.MapImageService">
<endpoint
address="https://gis.customer.com/StaticMapImage/Service/StaticMapImageService.svc"
binding="basicHttpBinding"
bindingNamespace="http://customer.com"
contract="StaticMapImageService.Data.IMapImageService"
listenUri="http://hq-gis01.customer.net/StaticMapImage/Service/StaticMapImageService.svc"
behaviorConfiguration="SSLLoadBalancerBehavior">
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
bindingNamespace="http://werner.com"
contract="IMetadataExchange"/>
</service>
</services>
There is no entry for this service in the system.servicemodel/bindings section. The other services are configured in the bindings and client sections:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAddressVerificationService"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferSize="999999999"
maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="BasicHttpBinding_IGeocoderService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="PCMilerSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IGeocoderService" 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="999999999"
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="https://gis.customer.com/AddressVerification/Service/AddressVerificationService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAddressVerificationService"
contract="AddressVerificationService.IAddressVerificationService"
name="BasicHttpBinding_IAddressVerificationService" />
<endpoint address="https://gis.customer.com/Geocoder/Service/GeocoderService.svc/ws"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IGeocoderService"
contract="GeocoderService.IGeocoderService" name="WSHttpBinding_IGeocoderService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="https://gis.customer.com/Geocoder/Service/GeocoderService.svc/soap"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGeocoderService"
contract="GeocoderService.IGeocoderService" name="BasicHttpBinding_IGeocoderService" />
<endpoint address="http://hq-miler02.customer.net/MultiMiler/ALKWS/PCMiler.asmx"
binding="basicHttpBinding" bindingConfiguration="PCMilerSoap"
contract="PCMiler.PCMilerSoap" name="PCMilerSoap" />
</client>
There was a problem when the service was deployed to a server behind the load balancer. When I try to call the service from WCFStorm or WebServiceStudio I get the message "The provided URI scheme 'https' is invalid; expected 'http'.
The endpoints for the service itself look right to me. However in the development and testing versions of the config, the client section uses http instead of http, while on the production servers it uses the load balancer's https address.
This seems like it should be obvious, but we're missing it. Can anybody give us a clue?
We have wcf services set up behind Windows Network Load Balancing without any issue (well there was one, but it wasn't to do with NLB).
I think it's to do with the address. The web server is usually unaware that it's behind a load balancer. all it sees are requests coming from one source, the load balancer. Your binding has it listening for https, but unless the load balancer talks to the web server over https, which is rare, the requests are coming over http, hence the error.
You need to either change the address to http, or set the load balancer to talk to the web server via http.
So I'm late to the party, but i ran into the same issue with calling a service behind F5. Change your client binding security to Transport instead of None.

WCF Authentication on the Internet

I have a WCF service using the basicHTTP binding. The service will be targeted to be deployed
in production in a DMZ environment on a Windows Server 2008 64 bit running IIS 7.0 and is not
in an Active Directory domain.
The service will be accessed by a business partner over the Internet with SSL protection. Originally,
I had built the service to use x.509 Message authentication with wsHTTPBinding and after a lot of
problems I punted and decided to back up and use basicHTTP with UserName authentication.
Result: same exact, obscure error message as I received with certificate mode.
The service works perfectly inside our domain with the exact same authentication but as soon as
I move it to the DMZ I get an error reading: "An unsecured or incorrectly secured fault was received
from the other party. See the inner FaultException for the fault code and detail".
The inner exception message is: "An error occurred when verifying security for the message."
The services' web config with binding configuration is as follows:
<services>
<service behaviorConfiguration="HSSanoviaFacade.Service1Behavior" name="HSSanoviaFacade.HSSanoviaFacade">
<endpoint address="" binding="basicHttpBinding" contract="HSSanoviaFacade.IHSSanoviaFacade" bindingConfiguration="basicHttp">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://FULLY QUALIFIED HOST NAME CHANGED TO PROTECT/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttp">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="HSSanoviaFacade.Service1Behavior">
<serviceMetadata httpsGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
The test client's configuration that gets the error:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IHSSanoviaFacade" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://HOST NAME CHANGED TO PROTECT"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHSSanoviaFacade"
contract="MembersService.IHSSanoviaFacade" name="BasicHttpBinding_IHSSanoviaFacade" />
</client>
As mentioned earlier, the service works perfectly on the domain and the production IIS box is not on a domain.
I have been tweaking and pulling my hair out for 2 weeks now and nothing seems to work. If anyone can help I
would appreciate it. Even a recommendation for a work around for authentication. I'd rather not use a custom
authentication scheme but use built-in SOAP capabilities.
The credentials pass in thru the proxy i.e. proxy.ClientCredentials.UserName.UserName and
proxy.ClientCredentials.UserName.Password are valid accounts on both the internal domain in the test
environment and as a machine account on the DMZ IIS box.
Well, maybe not exactly what I wanted but I got it to work. Must be a difference in IIS in a domain versus not.
Here are my changes to the service web config:
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
As I understand it, this doesn't pass the credentials in the SOAP header but in the HTTP header which means message level security doesn't work in this scenario. Its all protected by an SSL certificate.

Resources