Skip to content

Commit 788990c

Browse files
committed
Updated content, revised images
1 parent 115f3ed commit 788990c

File tree

4 files changed

+52
-60
lines changed

4 files changed

+52
-60
lines changed
Loading
Loading
Loading
Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
title: "Quickstart: Organization service sample (C#) (Microsoft Dataverse) | Microsoft Docs" # Intent and product brand in a unique string of 43-59 chars including spaces
3-
description: "This quick start will show you how to connect to the Organization service of Microsoft Dataverse." # 115-145 characters including spaces. This abstract displays in the search result.
4-
ms.date: 09/30/2022
5-
author: JimDaly
6-
ms.author: jdaly
2+
title: "Quickstart: Execute an Organization service request (C#) (Microsoft Dataverse) | Microsoft Docs" # Intent and product brand in a unique string of 43-59 chars including spaces
3+
description: "Demonstrates how to connect to the Organization service of Microsoft Dataverse and execute a request." # 115-145 characters including spaces. This abstract displays in the search result.
4+
ms.date: 10/05/2022
5+
author: phecke
6+
ms.author: pehecke
77
manager: kvivek
8-
ms.reviewer: pehecke
8+
ms.reviewer: jdaly
99
ms.topic: "article"
1010
search.audienceType:
1111
- developer
@@ -16,16 +16,17 @@ contributors:
1616
- JimDaly
1717
- phecke
1818
---
19-
# Quickstart: Organization service sample (C#)
19+
20+
# Quickstart: Execute an Organization service request (C#)
2021

2122
[!INCLUDE[cc-terminology](../includes/cc-terminology.md)]
2223

2324
This topic shows you how to begin using classes in the SDK for .NET assemblies to work with Microsoft Dataverse business data. You will create a minimal console application to connect to your environment's Organization service using the <xref:Microsoft.PowerPlatform.Dataverse.Client.ServiceClient> class and execute a web service operation.
2425

25-
Your application will call the <xref:Microsoft.Xrm.Sdk.IOrganizationService>.<xref:Microsoft.Xrm.Sdk.IOrganizationService.Execute*> method passing an instance of the <xref:Microsoft.Crm.Sdk.Messages.WhoAmIRequest> class. The result returned from the web service is a populated <xref:Microsoft.Crm.Sdk.Messages.WhoAmIResponse>.<xref:Microsoft.Crm.Sdk.Messages.WhoAmIResponse.UserId> value which is the identifier of your Dataverse user account.
26+
Your application will call the <xref:Microsoft.Xrm.Sdk.IOrganizationService>.<xref:Microsoft.Xrm.Sdk.IOrganizationService.Execute*> method passing an instance of the <xref:Microsoft.Crm.Sdk.Messages.WhoAmIRequest> class. The result returned from the web service is a populated <xref:Microsoft.Crm.Sdk.Messages.WhoAmIResponse>.<xref:Microsoft.Crm.Sdk.Messages.WhoAmIResponse.UserId> value which is the unique identifier of your Dataverse system user account.
2627

2728
> [!NOTE]
28-
> This quick start example does not include error handling for brevity. This is a minimum code example of what you need to connect to and use the Organization service.
29+
> This quick start example does not include exception handling for brevity. This is a minimum code example of what you need to connect to and use the Organization service.
2930
3031
## Prerequisites
3132

@@ -37,103 +38,94 @@ Your application will call the <xref:Microsoft.Xrm.Sdk.IOrganizationService>.<xr
3738

3839
## Create Visual Studio project
3940

40-
1. Create a new .NET console app project. For this project we are demonstrating .NET 6, but .NET Framework will also work.
41+
1. Create a new .NET console app project. For this project we are Visual Studio 2022 and targeting .NET 6, but .NET Framework will also work.
4142

4243
![Start a console app project.](../media/quick-start-org-service-console-app-1.png)
4344

44-
> [!NOTE]
45-
> This screenshot shows the name `OrgServiceQuickStart`, but you can choose to name the project and solution whatever you want.
46-
4745
1. In **Solution Explorer**, right-click the project you created and select **Manage NuGet Packages...** in the context menu.
4846

4947
![Add NuGet package.](../media/quick-start-org-service-console-app-2.png)
5048

51-
1. Browse for the latest version of the `Microsoft.CrmSdk.XrmTooling.CoreAssembly` NuGet package and install it.
49+
1. Browse for the latest version of the `Microsoft.PowerPlatform.Dataverse.Client` NuGet package and install it.
5250

53-
![Install Microsoft.CrmSdk.XrmTooling.CoreAssembly NuGet package.](../media/quick-start-org-service-console-app-3.png)
51+
![Install Microsoft.PowerPlatform.Dataverse.Client NuGet package.](../media/quick-start-org-service-console-app-3.png)
5452

5553
> [!NOTE]
56-
> You must select **I Accept** in the **Licence Acceptance** dialog.
54+
> Your will be prompted to OK the preview changes, and then select **I Accept** in the **Licence Acceptance** dialog.
5755
58-
## Edit Program.cs
56+
## Add application code
5957

60-
1. Add these using statements to the top of `Program.cs`
58+
1. In **Solution Explorer**, double-click Program.cs to edit that file. Replace the file's contents with the code shown below.
6159

6260
```csharp
6361
using Microsoft.Crm.Sdk.Messages;
64-
using Microsoft.Xrm.Tooling.Connector;
65-
```
66-
67-
1. Replace the `Main` method with the following code. The supported values for *AuthType* are listed in [Connection string parameters](../xrm-tooling/use-connection-strings-xrm-tooling-connect.md).
68-
69-
```csharp
70-
static void Main(string[] args)
71-
{
72-
// e.g. https://yourorg.crm.dynamics.com
73-
string url = "<your environment url>";
74-
75-
string userName = "<your user name>";
76-
// e.g. y0urp455w0rd
77-
string password = "<your password>";
78-
79-
string conn = $@"
80-
Url = {url};
62+
using Microsoft.PowerPlatform.Dataverse.Client;
63+
64+
class Program
65+
{
66+
// TODO Enter your Dataverse environment's URL and logon info.
67+
static string url = "https://yourorg.crm.dynamics.com";
68+
static string userName = "[email protected]";
69+
static string password = "password";
70+
71+
// This service connection string uses the info provided above.
72+
// The AppId and RedirectUri are provided for sample code testing.
73+
static string connectionString = $@"
8174
AuthType = OAuth;
75+
Url = {url};
8276
UserName = {userName};
8377
Password = {password};
8478
AppId = 51f81489-12ee-4a9e-aaae-a2591f45987d;
8579
RedirectUri = app://58145B91-0C36-4500-8554-080854F2AC97;
8680
LoginPrompt=Auto;
8781
RequireNewInstance = True";
8882

89-
using (var svc = new CrmServiceClient(conn))
83+
static void Main(string[] args)
9084
{
91-
92-
WhoAmIRequest request = new WhoAmIRequest();
93-
94-
WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request);
95-
96-
Console.WriteLine("Your UserId is {0}", response.UserId);
97-
85+
using (ServiceClient serviceClient = new(connectionString))
86+
{
87+
if (serviceClient.IsReady)
88+
{
89+
WhoAmIResponse response =
90+
(WhoAmIResponse)serviceClient.Execute(new WhoAmIRequest());
91+
92+
Console.WriteLine("User ID is {0}.", response.UserId);
93+
}
94+
else
95+
{
96+
Console.WriteLine(
97+
"A web service connection was not established.");
98+
}
99+
}
100+
101+
// Pause the console so it does not close.
98102
Console.WriteLine("Press any key to exit.");
99103
Console.ReadLine();
100104
}
101105
}
102106
```
103107

104-
1. Edit the following values to add information for your environment. You can find your environment URL in the Web application under **Settings > Customization > Developer Resources**.
105-
106-
```csharp
107-
// e.g. https://yourorg.crm.dynamics.com
108-
string url = "<your environment url>";
109-
110-
string userName = "<your user name>";
111-
// e.g. y0urp455w0rd
112-
string password = "<your password>";
113-
```
108+
1. Change the values for the environment URL, username, and password as indicated by the TODO code comment.
109+
You can find supported values for *AuthType* listed in [Connection string parameters](../xrm-tooling/use-connection-strings-xrm-tooling-connect.md). You can find your environment URL in the legacy web application under **Settings > Customization > Developer Resources** or in Power Apps **Settings** (gear icon) > **Developer Resources**.
114110

115111
## Run the program
116112

117113
1. Press F5 to run the program. The output should look like this:
118114

119115
```bash
120-
Your UserId is 969effb0-98ae-478c-b547-53a2968c2e75
116+
User ID is 969effb0-98ae-478c-b547-53a2968c2e75
121117
Press any key to exit.
122118
```
123119

124-
### Congratulations!
125-
126-
You have successfully connected to the organization service.
127-
128120
## Next Steps
129121

130-
These articles will explain how to work with Dataverse tables:
122+
The console app demonstrated how to connect to the Organization web service using a connection string, execute a web service message request, and access some data in the response. Next, you may want to look at common web service data operations like create, retrieve, update, and delete.
131123

124+
The following articles will explain how to work with business data in Dataverse tables.
132125
[Entity class operations using the Organization service](entity-operations.md)<br />
133126
[Create table rows using the Organization Service](entity-operations-create.md)<br />
134127
[Retrieve a table row using the Organization Service](entity-operations-retrieve.md)<br />
135128
[Update and delete table rows using the Organization Service](entity-operations-update-delete.md)<br />
136129
[Associate and disassociate table rows using the Organization Service](entity-operations-associate-disassociate.md)
137130

138-
139131
[!INCLUDE[footer-include](../../../includes/footer-banner.md)]

0 commit comments

Comments
 (0)