WCF Data Services

by Raju Maharjan 7. August 2011 17:11

WCF Data Services (originally known as ADO.NET Data Services) is a framework for exposing data layers in a REST-ful manner, using JSON or Atom as the output format. WCF Data Services is a component of the .NET Framework that enables you to create services that use the Open Data Protocol (OData) to expose and consume data over the Web or intranet by using the semantics of REST (Representational State Transfer). OData exposes data as resources that are addressable by URIs. Data is accessed and changed by using standard HTTP verbs of GET, PUT, POST, and DELETE. OData uses the entity-relationship conventions of the Entity Data Model to expose resources as sets of entities that are related by associations.

While the technology is relatively new, it addresses a number of common use cases for developers, including:

  • Allow AJAX applications access to the database via HTTP without writing a Web service as a proxy.
  • Provide access to data to third-parties in a standardized, vendor neutral fashion.
  • Create a REST-ful data access system without the baggage of other Web service systems.
The technology automatically creates a REST-ful Web service that emits JSON or Atom based on a provided configuration. This means that the developer is now off the hook for writing an entire Web service, serializing the data to JSON or Atom, and so on, which can save significant amounts of time. 
  1. uses the OData protocol for addressing and updating resources. In this way, you can access these services from any client that supports OData. OData enables you to request and write data to resources by using well-known transfer formats: Atom, a set of standards for exchanging and updating data as XML, and JavaScript Object Notation (JSON), a text-based data exchange format used extensively in AJAX application.
  2. can expose data that originates from various sources as OData feeds. Visual Studio tools make it easier for you to create an OData-based service by using an ADO.NET Entity Framework data model. You can also create OData feeds based on common language runtime (CLR) classes and even late-bound or un-typed data.
  3. includes a set of client libraries, one for general .NET Framework client applications and another specifically for Silverlight-based applications. These client libraries provide an object-based programming model when you access an OData feed from environments such as the .NET Framework and Silverlight. 

Tags: ,

OData | WCF | Web Services

Free memory (14618624 bytes) is less than 5% of total memory in WCF

by Raju Maharjan 18. June 2011 14:38

 

If you ever received the below error while accessing your WCF servcie, then it is most likely that your server is having very low free memory. In this case, one of the main reason could be some big application running on the server consuming most of the memory.

So best way to get rid of this problem could be increase the memory for your server. In the other hand, you may uninstall the undesired applications running at your server.

 

Server Error in 'yourdomain/app' Application.


Memory gates checking failed because the free memory (14618624 bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InsufficientMemoryException: Memory gates checking failed because the free memory (14618624 bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[InsufficientMemoryException: Memory gates checking failed because the free memory (14618624 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.]
System.ServiceModel.Activation.ServiceMemoryGates.Check(Int32 minFreeMemoryPercentage) +51455
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +604

[ServiceActivationException: The service '/staging/coresecurityservice/coresecurityservice.svc' cannot be activated due to an exception during compilation. The exception message is: Memory gates checking failed because the free memory (14618624 bytes) is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element..]
System.Runtime.AsyncResult.End(IAsyncResult result) +679246
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +300622
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +8837348

 

You can also update your wcf configuration files for the required parameters and also set minFreeMemoryPercentageToActivateService  in ServiceHostingEnvironment

<serviceHostingEnvironment>
         aspNetCompatibilityEnabled="Boolean"
       minFreeMemoryPercentageToActivateService="Integer"
     <baseAddressPrefixFilters>
                <add prefix="string"/>
          </baseAddressPrefixFilters>
     <transportConfigurationTypes>
        <add name="String" 
             transportConfigurationType="String" />
     </transportConfigurationTypes>
</serviceHostingEnvironment>

 

Set the minimum free memory percentage according to your  needs:

 

minFreeMemoryPercentageToActivateService="1" //for minimum 1% of Free memeory

 

 

minFreeMemoryPercentageToActivateService   is an integer that specifies the minimum amount of free memory that should be available to the system, before a WCF service can be activated.

 

BasicHttpBinding vs. WSHttpBinding

by Raju Maharjan 11. June 2011 02:01

WSHttpBinding messaging is based on SOAP 1.2 and WS-Addressing Specifications while BasicHttpBinding messaging is based on SOAP 1.1 specifications. Implementing the WS-Addressing specifications enables more features in this binding like asynchronous messaging, message correlation, and transport-neutral addressing mechanisms which for sure adds some processing overhead.

BasicHttpBinding provides fewer security options which are Message security, User name token,  Kerberos and X509 tokens. WSHttpBinding provides more in addition to the list above which are WS-Trust and WS Secure conversation.

BasicHttpBinding doesn't supported reliable messaging. In other words, if a client fires two or three calls you really do not know if they will return back in the same order. In the other hand, WSHttpBinding  supports WS-* specifications.

By default,in BasicHttpBinding there is no security provided for messages when the client calls happen. In other words, data is sent as plain text. As WSHttpBinding supports WS-*, it has WS-Security enabled by default. So the data is not sent in plain text.

BasicHttpBinding supports the following security options:

  • None
  • Windows – default authentication
  • Basic
  • Certificate

WSHttpBinding supports the following security options

 

  • None
  • Transport
  • Message
  • Transport with message credentials

 

Tags: ,

WCF | Web Services

Difference between Web Reference and Service Reference

by Raju Maharjan 2. December 2010 16:38

Visual Studio provides Web references. Web references differ from traditional references and components; instead of referencing a component or a class library installed on the local computer, a Web reference provides access to a resource that is available using an Internet protocol such as SOAP or HTTP.  Web reference is a generated proxy class that locally represents the exposed functionality of an XML Web service. Web Reference allows you to communicate with any service based on any technology that implements the WS-I Basic Profile 1.1, and exposes the relevant metadata (WSDL). Internally, it uses the ASMX communication stack on the client side. Add Web Reference is a wrapper over wsdl.exe and can be used to create proxies for .NET 1.1 or 2.0 clients. Of course this means when you are pointing to a WCF service you have to be pointing to an endpoint that uses basicHttpBinding.

A Service Reference allows you to communicate with any service based on any technology that implements any of the many protocols supported by WCF (including but not limited to WS-I Basic Profile). Internally, it uses the WCF communication stack on the client side. Add Service Reference is a wrapper over svcutil.exe and also creates clients proxies (and additionally web.config entries). These proxies, however, can only be consumed by .NET 3.0+ clients.If you are working with a WCF service application and the project contains a handful of simple data contracts, then you possibly won't encounter any problem in using the Add Service Reference feature of Visual Studio to generate service proxies. However, there might come a time when you need to use inheritance or circular references in your data contracts. In these cases, creating service proxies manually might be a better option than using the Add Service Reference dialog.

It is perfectly possible (though not recommended) to add a Web Reference that points to a WCF service, as long as the WCF endpoint uses basicHttpBinding or some compatible custom variant.

Below image will show you how to add web reference from Service Reference. Right click the Service References from solution explorer, then select advance button on Add Services window you will get to the form as in below image and then will be able to add Web Reference via Add web Reference window.

Difference between Web Reference and Service Reference

It is also possible to add a Service Reference that points to an ASMX service. When writing new code, you should always use a Service Reference simply because it is more flexible and future-proof.

 

Tags: ,

WCF | Web Services


Sapnep IT Solution

We Provide IT solutions and services to deliver a unique blend of real-business experience with a strong engineering, international project delivery. We are a software development  firm.