Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home CSharp Create CrmService with Domain, Username And Password

Create CrmService with Domain, Username And Password

Before you can call CrmService Web methods ex: Create, Retrieve, RetrieveMultiple, Update, Delete and Fetch, you have to create a CrmService instance.

This tutorial will show you step by step on how to create CrmService by using CrmDiscoveryService Web service with an Internet Facing Deployment (IFD) of Microsoft Dynamics CRM.

1. You need to download Microsoft Dynamics CRM 4.0 Software Development Kit (SDK)

2. Add the CrmDiscoveryService Web Reference:

+ Option 1:

  • Open Internet Explorer and enter the following URL: https://dev.crm.dynamics.com/MSCRMServices/2007/Passport/CrmDiscoveryService.asmx?WSDL
  • In the File menu, click Save As.
  • Name the file CrmDiscoveryService.wsdl and save it to an appropriate location on your computer, ex: C:\Users\Hoan Huynh\Desktop\sdk\wsdl.
Download CrmDiscoveryService WSDL

Download CrmDiscoveryService WSDL

+ Option 2:

Copy the file CrmDiscoveryService.wsdl from the sdk/wsdl folder which you just dowloaded from step 1

CrmDiscoveryService WSDL

CrmDiscoveryService WSDL

3. Add the Web Reference to your Visual Studio Project

  • Create a C# or Visual Basic .NET project in Microsoft Visual Studio.
  • In Solution Explorer, right-click References.
  • Select Add Web Reference.
    Add Web Reference

    Add Web Reference

  • In the URL field, enter the path to the CrmDiscoveryService.wsdl file: file://C:\Users\Hoan Huynh\Desktop\sdk\wsdl\crmdiscoveryservice.wsdl
  • Click Go.
  • Edit the Web reference name, ex: CRM. This is the name that you will put in the Using statement in the source code.
  • Click Add Reference.
Add-Web-Reference-Edit-Name

Add-Web-Reference-Edit-Name

4. Add Assemblies

We need to add 3 Assemblies below to your project:

  • Microsoft.Crm.Sdk.dll
  • Microsoft.Crm.SdkTypeProxy.dll
  • microsoft.crm.sdktypeproxy.xmlserializers.dll

The assemblies can be found in the SDK folder which was downloaded from step 1 (SDK\Bin or SDK\Bin\64-bit)

Add Assemblies

Add Assemblies

5. Create IFDConnection function

This step is the main part of this tutorial which will show the function to create a CrmService instace.

We will create the function in a new class file named: crm_demo.cs

And we need to using some new namespace:

[csharp] using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using CRM;
[/csharp]

The function is below:

[csharp] public CrmService IFDConnectionDemo(string organization, string server, string domain, string username, string password)
{
// A CrmService reference.
CrmService CrmService = null;
// URL of the Web application.
string WebApplicationUrl = String.Empty;
// GUID of the user’s organization.
Guid OrganizationId = Guid.Empty;
//Remove any trailing forward slash from the end of the server URL.
server = server.TrimEnd(new char[] { ‘/’ });
// Initialize an instance of the CrmDiscoveryService Web service proxy.
CrmDiscoveryService disco = new CrmDiscoveryService();
disco.Url = "http://" + server + "/MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx";
//Retrieve a list of available organizations.
RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
orgRequest.UserId = domain + "\\" + username;
orgRequest.Password = password;
RetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)disco.Execute(orgRequest);
//Find the desired organization.
foreach (OrganizationDetail orgdetail in orgResponse.OrganizationDetails)
{
if (orgdetail.OrganizationName.ToLower() == organization.ToLower())
{
//Retrieve the ticket.
RetrieveCrmTicketRequest ticketRequest = new RetrieveCrmTicketRequest();
ticketRequest.OrganizationName = organization;
ticketRequest.UserId = domain + "\\" + username;
ticketRequest.Password = password;
RetrieveCrmTicketResponse ticketResponse = (RetrieveCrmTicketResponse)disco.Execute(ticketRequest);
//Create the CrmService Web service proxy.
CrmAuthenticationToken sdktoken = new CrmAuthenticationToken();
sdktoken.AuthenticationType = 2;
sdktoken.OrganizationName = organization;
sdktoken.CrmTicket = ticketResponse.CrmTicket;
CrmService = new CrmService();
CrmService.CrmAuthenticationTokenValue = sdktoken;
CrmService.Url = orgdetail.CrmServiceUrl;
WebApplicationUrl = orgdetail.WebApplicationUrl;
OrganizationId = orgdetail.OrganizationId;
break;
}
}
return CrmService;
}
[/csharp]

6. Testing the IFDConnectionDemo function

Create a new aspx page named: test_crm_service.aspx with content below:

[csharp] using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using CRM;

public partial class test_crm_service : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string organization = "your-organization";
string server = "your-server:your-port-number-if-any";
string domain = "your-domain";
string username = "your-username";
string password = "your-password";

CrmService service = crm_demo.IFDConnectionDemo(organization, server, domain, username, password);
}
}
[/csharp]

That’s all, now you can call all CrmService web methods: Create, Retrieve, RetrieveMultiple, Update, Delete and Fetch

Download the source code for the tutorial includes all necessary *.dll and .wsdl file

Mar 25, 2011Hoan Huynh
Top Free Real Time Website Analytics Services And ToolsCreate Account With Microsoft Dynamics CRM Web Services By C#
You Might Also Like:
  • Create Account With Microsoft Dynamics CRM Web Services By C#
  • Retrieve Account With Microsoft Dynamics CRM Web Services By C#
  • Create And Assign Account To A User In Microsoft Dynamic CRM With C#
  • Dymanic Crm Error 401 Unauthorized When Create Or Retrieve Account And Contact
  • Create Amazon CloudFront With Your Own Domain And Own Files Server
  • Asp.net C# Create MD5 Hash
  • Property or indexer ‘Microsoft.Crm.Sdk.Query.ColumnSet.Attributes’ cannot be assigned to – it is read only
  • How To Filter DataBase Name And Login Username In SQL Server Profiler
  • MSSQL Create Database With SQL Statement
  • Create A Strong Password With Rules And Recommendations
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

10 years ago CSharpCrmService, Microsoft, Microsoft Dynamics CRM, SDK414
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
22,167 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
20,044 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,824 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,306 views
C# Read Json From URL And Parse/Deserialize Json
9,793 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • How to Compose Your Essay To Me – 4 Easy Steps to Write My Essay
  • How to Find a Photo Editor
  • Installment Loans – Making Sense of Online Software
  • Apple Pay Casino Canada
  • Casinos austria
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (105)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development