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

Invalid postback or callback argument

by Raju Maharjan 4. August 2011 15:30

Server Error in '/' Application.

--------------------------------------------------------------------------------

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

In the context of the data controls, this happens when a control that isn't registered for event validation causes a postback, but surely that can't be the case.. right?


The reason this happens is because we rebind the data control in Page_Load every time which means that we will lose all of the posted data and viewstate. As a result, the ID of the Control is different and when the event is validated there will be no matching unique id and hence event validation will fail. We are acutally raising an event for a button that is no longer in the control tree.

You can work around this by wrapping that code in if (!IsPostBack). This is a good proof of why you should use DataSource controls.

Tags:

ASP.NET

OData - Open Data Protocol

by Raju Maharjan 23. July 2011 20:33

The Open Data Protocol (OData) is an open web protocol for querying and updating data. The protocol allows for a consumer to query a datasource over the HTTP protocol and get the result back in formats like AtomJSON or plain XML, including pagination, ordering or filtering of the data. OData is being used to expose and access information from a variety of sources, including but not limited to relational databases, file systems, content management systems, and traditional web sites. Microsoft has released OData under the Open Specification Promise (OSP) to allow anyone to freely interoperate with OData implementations. We intend on working with others in the community to move the features of OData into future version of AtomPub or other appropriate standards.

OData is defined as a set of open extensions/conventions to AtomPub documented and released under the OSP (Open Specification Promise).  

There is a growing list of products that implement the Open Data Protocol. Microsoft supports OData in SharePoint Server 2010, Excel 2010 (through SQL Server PowerPivot for Excel), Windows Azure Storage, SQL Server 2008 R2,Visual Studio 2008 SP1 and the .NET Framework. Microsoft provides client libraries for .NET, Silverlight, AJAX. Support in other Microsoft products is currently underway. Client libraries are also available for .NET, Silverlight, Windows Phone 7, PHP, AJAX, Javascript, Ruby, Objective C and Java.

Since the Open Data Protocol is fully specified, you can implement on any HTTP server using any language. On the .NET Framework, WCF.NET Data Services provides a framework allowing developers to create a OData services in .NET. Likewise in Java there is a server library called OData4J. As noted above, client libraries are available for .NET, Silverlight, Windows Phone 7, PHP, AJAX, Javascript, Ruby, Objective C and Java

There is a growing list of products that implement OData. Microsoft supports the Open Data Protocol in SharePoint Server 2010, Excel 2010 (through SQL Server PowerPivot for Excel), Windows Azure Storage, SQL Server 2008 R2, Visual Studio 2008 SP1. Support in other Microsoft products is currently underway.

 

Tags: ,

OData

SaaS - Software as a Service

by Raju Maharjan 28. June 2011 01:07

Software as a Service, SaaS is a software delivery method that provides access to software and its functions remotely as a Web-based service.  Software as a Service may also be referred to as simply hosted applications. Software as a Service allows organizations to access business functionality at a cost typically less than paying for licensed applications since SaaS pricing is based on a monthly fee. Software as a Service removes the need for organizations to handle the installation, set-up and often daily upkeep and maintenance. Also, because the software is hosted remotely, users don't need to invest in additional hardware. 

In other words, SAAS is a software delivery model in which software and its associated data are hosted centrally (typically in the Internet cloud) and are typically accessed by users using a thin client, normally using a web browser over the Internet.

Tags: ,

SAAS

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

How to retrieve data from entity (table) in SageCRM?

by Raju Maharjan 1. December 2010 22:01

With queryrecord method you will be able to retrieve the list of the records from entity. It is pretty simple to build your own SQL query while dealing with the queryrecordRequest  object of your web service. All you need to do is set fieldlist, entityname, queryString ,orderby and SessionHeader  properties exposed in the object and you will build your custom query to retrieve records for the entity.

SessionHeader crmSessionHeader = new SessionHeader();

WebServiceSoapPort CRMService = new WebServiceSoapPortClient();

void GetAllRecordsInEntity()

        {

            string listofFields = "";// blank will return all the fields or you can set the comma separated column names;

            string whereClause = "";//" blank for no condition or set as "type='user'" for condition

            string entityName = "Users";// Define entity name (which is a database table) here 

            string orderBy = "";// set  order by with desired column

 

            queryrecordResponse objQueryRecordResponse = new queryrecordResponse();

            queryrecordRequest objQueryRecordRequest = new queryrecordRequest();

            objQueryRecordRequest.fieldlist = listofFields;

            objQueryRecordRequest.entityname = entityName;

            objQueryRecordRequest.queryString = whereClause;

            objQueryRecordRequest.orderby = orderBy;

            objQueryRecordRequest.SessionHeader = crmSessionHeader;            

            objQueryRecordResponse = CRMService.queryrecord(objQueryRecordRequest);

            queryrecordresult myQueryRecordResult = objQueryRecordResponse.result;            

            crmrecord[] myRecordList = myQueryRecordResult.records;            

            for (int i= 0; i< myRecordList.Length; i++)

            {

                recordfield[] myFieldList = myRecordList[i].records;

                for (int j= 0; j< myFieldList.Length; j++)

                {

                    recordfield myField = (recordfield)myFieldList[j];

                   //use myField.name for column name and  myField.value for value field

                }

            }

        }

 

Domain Registration, Web Hosting and Web Services 
Domain Registration, Web Hosting and Reseller Web Hosting 
Start Web Hosting from just $2.5/Month

Tags: , , ,

SageCRM

How to set MaxReceivedMessageSize property in Sage CRM Service application?

by Raju Maharjan 1. December 2010 18:30

If you even faced the exception message as below while developing application using SageCRM web services then here is the solution.

"To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."

Find  the below section in your app.config or web.config within your application.

<system.serviceModel>

        <bindings>

            <basicHttpBinding>

                <binding name="WebServiceSoapBinding" 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> 

You can find the property as maxReceivedMessageSize="65536"  which is set by default to 65536. You may change this property as per your need.

 

Domain Registration, Web Hosting and Web Services 
Domain Registration, Web Hosting and Reseller Web Hosting 
Start Web Hosting from just $2.5/Month

Tags: ,

SageCRM

How to Logon / Logoff using Web Service in Sage CRM and Add Service Reference?

by Raju Maharjan 30. November 2010 19:08

If you have used 'Add Service Reference' to connect to a Sage CRM with VS2008 then you will be using the WebServiceSoapPort class. Before beginning with the development firstly add reference to the web service by simply right clicking the project solution explorer and then Add Service Reference. The below window appears and put you reference URL.

How to Logon using Web Service in Sage CRM and Add Service Reference?

 

Log on (WebServiceSoapClient)

WebServiceSoapPort SageCRMService = new WebServiceSoapPortClient();
logonRequest objLogonRequest = new logonRequest();

//Set your CRM Username and Password
objLogonRequest .username = "CRMAdminUser";
objLogonRequest .password = "yourCrmPassword";
logonResponse objLogonResponse = SageCRMService .logon(objLogonRequest );

SessionHeader objSessionHeader = new SessionHeader();
objSessionHeader.sessionId = objLogonResponse .result.sessionid;

Log off (WebServiceSoapClient)

logoffRequest objLogoffRequest = new logoffRequest();

objLogoffRequest .SessionHeader = objSessionHeader;
objLogoffRequest .sessionId=objLogonResponse .result.sessionid;
logoffResponse objLogoff = SageCRMService.logoff(objLogoffRequest);

By implementing in code as above you will be able to Logon and LogOff in SageCRM. The steps are pretty simple to use but make sure that the logon user must have Web Service access and CRM Web Services are setup.

To set up a user for Web Services:

1. Select Administration | Users | Users and find the user who you want to be able to access

Web Services.

2. Select the hypertext link for the user and select the Change action button.

3. Scroll down to the Security Profile panel, set the Allow Web Service Access field to True.

4. Select the Save button.

 

Domain Registration, Web Hosting and Web Services 
Domain Registration, Web Hosting and Reseller Web Hosting 
Start Web Hosting from just $2.5/Month


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.