Writing Web Service for MS CRM Data Access


Using MS CRM SDK which gives us access to the entities of the CRM, Which provide us a CRUD operations

Making an other web app which will use the service for displaying, create, delete and update the data of MS CRM


  • Providing a service which can let the user or any application perform CRUD operations
  • Providing an interface which show the CRUD operations on the basis of that service

Problems Encountered

  • Query Execution Time Problem
  • Learning LINQ Queries

Understanding the LINQ queries by reading the article written here

http://www.codeproject.com/Articles/38010/CRUD-Operations-using-LINQ-Entities#Step 2:- Create using LINQ


private Dictionary<Guid, String> _recordIds = new Dictionary<Guid, String>();
private OrganizationServiceProxy _serviceProxy;
private IOrganizationService _service;
public void createContact(){
Account account = new Account
Name = "Fourth Coffee",
Address1_StateOrProvince = "Colorado",
_recordIds.Add(_service.Create(account), Account.EntityLogicalName);

This is a snippet from SDK sample class CreateALinqQuery.cs
Its giving me the Null pointer exception, How do I put values in _recordlds?

similar way I can create Contact

Exception Handling Link

LINK Which mentions the how to handle the Null pointer Exception but we have some other kind of problem, Which is
We create a dictionary object and put those created accounts in that before we put any account in there it gives the error about null pointer exception which is why having problem.
Posted the problem in facebook MS CRM group and on the Microsoft Social forum for CRM 


Found that MS CRM has its own service for CRUD operations to perform. Which is IOrganizationService and they have Sample Code too which explains the Whole situation

Need to read the docs and how to use of that code

So what has been decided after discussing the situation with senior that I should continue my work on Interface with the service I have made with 2 or 3 things running using Linq Queries
So now I’ll work for a Webpage which will get data from the service and display it on the Page!

Learning ASP

Having problems with the ASP .net I was considering it like PHP but it had too much confusion with it, But now i have written hello world program.
Tasks are

  • Event Handling in JSP
  • Sending the string to the Service class
  • Getting the data
  • Displaying it in the Interface





  • Fixing the problem with the CRM Service With GUI
  • What was the problem [There is a facebook group question i’ll post here]
  • Issues with Web config which was using service tags had to be removed
  • code is working now and displaying the information of a user on a webpage
  • Next task is to parse the data and show it there in a proper way

Learning about the parsing and considering if Object can be turned into json if yes then i’ll use that one,

Links are




Today 0/23/2014 I updated the Code on bitbucket and deleted the old buggy code

This code which shows how to split the strings

//All the parsing happens here :D
public string ParsingString(String result )

//parsing the string here
char[] delimiterChars = { ‘ ‘, ‘,’, ‘.’, ‘:’, ‘\t’ };

string text = result;
System.Console.WriteLine(“Original text: ‘{0}'”, text);

string[] words = text.Split(delimiterChars);
System.Console.WriteLine(“{0} words in text:”, words.Length);

foreach (string s in words)

// Keep the console window open in debug mode.
System.Console.WriteLine(“Press any key to exit.”);

string displayString=”Results comes here”;

return displayString;

To parse the data the aproah which splits the string one by on which seems bad way to do it,
I looked for something better which would be like
convert the object data into json and then get the values from jason by doing

string name= jsonObjectWhcihHoldsTheValues["Name"];

The problem was
Remotely Publishing/deploy the project using Visual Studio http://msdn.microsoft.com/en-us/library/cdt9aht6(v=vs.90).aspx


IIS .net Version of application http://technet.microsoft.com/en-us/library/cc754523(v=ws.10).aspx
Tomcat Port http://www.mkyong.com/tomcat/how-to-change-tomcat-default-port/

Web deployment task failed. (The application pool that you are trying to use has the 'managedRuntimeVersion' property set to 'v2.0'. This application requires 'v4.0'. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_APPPOOL_VERSION_MISMATCH.)

This problem was solved by changing the version of the .net to the 4.0

*Publishing the Project Problem

Application was running the version i code before but then I improved the code added exception handling, put some checks and clean the code. After that I needed to deploy the latest version of the code. Then I struct with a problem which is at the msdn forum


I am trying to publish a project on a remote server and getting this error

2>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets(4255,5): Warning : An error was encountered when processing operation 'Delete File' on 'u_ex141016.log'.  
2>Retrying operation 'Delete' on object filePath (crm-crud/logs\wmsvc\W3SVC1\u_ex141016.log). Attempt 1 of 2.
2>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets(4255,5): Warning : An error was encountered when processing operation 'Delete File' on 'u_ex141016.log'.  
2>Retrying operation 'Delete' on object filePath (crm-crud/logs\wmsvc\W3SVC1\u_ex141016.log). Attempt 2 of 2.
2>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets(4255,5): Error ERROR_FILE_IN_USE: Web deployment task failed. (The file 'u_ex141016.log' is in use.  Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE.)
2>Publish failed to deploy.

Did some googling on it but found nothing useful

This Question‘s answer suggest find the process and kill it, while i am seeing nothing like “u_ex141016.log” in processes so how do I kill it?

I deleted the log file going into the directory “inetpub/logs/wmsvc/W3SVC1/” but it didnt do anything still the error persist.

tried this one too


I tried stopping the server and tried but the same.

Using Visual Studio 2013

How do you suggest me to do it?

now I am resolving this problem will update the log when I’ll solve this

Final working configuration are shown in the snapshot

final working configurations

Installing MS SQL and MS CRM


MS CRM on Premise

Microsoft Dynamics CRM Online Docs


A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) Access is denied




Had to select the EFCRM-DEV

Active Directory

After setting up everything now facing the problem
404 error of CRM

Possible Solutions

  • same kind of problem I faced last time too,  Need to add the user in AD
  • Checking all services running fine ? (Checked it Everything Running fine)
  • Checking if IIS is running ?(IIS is running )

Or Putting that problem on CRM Forum
After Putting that on forum  Continue reading

MS CRM Logging

Plan of Action:

Writing a web service which gets request from finese and fetch the data from the MS Dynamics CRM

Problems to solve today:

1- Query Execution Time

2- Picking the multiple contacts if they have same phone number

Smaller Issues & Learning facing 

Links to study: