Connecting and Consuming CRM webservices using WCF component
Being new to MS CRM environment and with my naive C# skills, i struggled my bit to create WCF component to connect/consume CRM web services.
In this blog, I will go through all the required steps from start to end. Also many resources are available for reference in bits and pieces, I thought of putting everything at one place.
Motive behind developing WCF component :
We have users with out much knowledge of CRM and its terminology. we wanted a simplified, lite web application that our users can use with ease. Also we have multiple web components that are connecting to CRM. Hence we zeroed on developing WCF component which consumes CRM services. By hosting this WCF service, any one with corresponding link and credentials could connect/consume CRM services with out bothering much technical details. Also different user groups should be made to access only specific services. Also instead of using CRM DB context with LINQ queries, CRM Services will make developer life easier. As developer need not learn LINQ programming separately.
Step 1: Getting the services URI's
URI's for MS CRM RESTend & SOAP will be specified under
In this blog, I will go through all the required steps from start to end. Also many resources are available for reference in bits and pieces, I thought of putting everything at one place.
Motive behind developing WCF component :
We have users with out much knowledge of CRM and its terminology. we wanted a simplified, lite web application that our users can use with ease. Also we have multiple web components that are connecting to CRM. Hence we zeroed on developing WCF component which consumes CRM services. By hosting this WCF service, any one with corresponding link and credentials could connect/consume CRM services with out bothering much technical details. Also different user groups should be made to access only specific services. Also instead of using CRM DB context with LINQ queries, CRM Services will make developer life easier. As developer need not learn LINQ programming separately.
Step 1: Getting the services URI's
URI's for MS CRM RESTend & SOAP will be specified under
- Settings --> Customization --> Developer Resources
RESTend URI will be of form https://{your server name}/XRM/XRMServices/2011/Organizationdata.svc/
This section will provide WSDL URI's for SOAP and REST protocols.
SOAP Vs REST
using RESTend points is easy and straight forward( no need of C#/controller methods). It can be bind to frond end controls using Java Script/J Query. However handling security in web context is not that efficient. Also developing complex business logic can't be done.
RESTend points were introduced to avoid usage of fetchXML to perform small operations, which has many limitations. REST services can be used by creating JAVA Script(in CRM context we refer it as JScript) file in Settings --> customization --> Resources Section. This script can be used in any CRM web form to retrieve/insert/update data.
REST services follow ODATA protocol for data representation. RESTend points URI should be appended with corresponding table name and required operations.
$top |
The maximum number of items returned in the result set for each page.
|
$skip |
The number of rows to skip in the result set before beginning to return results.
|
$filter |
|
$orderby |
Specifies the sort order of the result set.
NOTE: Requires DataServiceVersion 2.0 or higher. To determine DataServiceVersion see Determine DataServiceVersion later in this topic. |
$select |
Specifies the fields returned in the result set.
|
$skiptoken |
An opaque value that must be passed back to the server in order to continue getting results for the query. For more information seeSkip Token System Query Option ($skiptoken) at OData.org.
|
$count |
Returns the count of a collection of entities.
NOTE: Requires DataServiceVersion 2.0 or higher. To determine DataServiceVersion see Determine DataServiceVersion in this topic. |
$inlinecount | $inlinecount is only supported for flexible query services. It is not supported for fixed query services.NOTE: Requires DataServiceVersion 2.0 or higher. To determine DataServiceVersion see Determine DataServiceVersion later in this topic. |
$metadata |
Retrieves a list of fields, their data types, mode, and other related information in a dataset.
|
ID operators
|
E.g.
"/Companies('Microsoft')" |
Comparison operators
| eq – Equal tone – Not equal tolt – Less thanle – Less than or equal togt – Greater thange – Greater than or equal to |
Logical operators
| and – True only if both operands are trueor – True if either or both operands are truenot – opposite of operand |
Arithimetic operators
| add – Addition operatorsub – Subtraction operatormult – Multiplication operatordiv – Division operatormod – Modulo (remainder after integer division) operator |
Grouping operators
| ( and ) |
DateTime Functions
| year month day hour minute second |
Math functions
| round ceiling floor |
SOAP services provides better security options while connecting to CRM.
1. Active Director authentication
2. IFD authentication
3. Live/on-line authentication
If your Organizations CRM authentication method is set to AD, we have to use Discovery URL with AD options. When connecting to CRM with authentication from web-form/WCF component, we have to use IFD method. When customers log in using Microsoft Live Id, we will go for Live authentication. These methods are explained in detail in later part.
The corresponding URI's will be
The corresponding URI's will be
Comments
Post a Comment