Dynamics CRM 2015/2016 Web api:unbound action and Bound action

Source: Internet
Author: User

The Bound/unbound Function is described in the previous article. Let's take a look at action today. As I said before: the difference between function and action is simple to understand. The function does not alter the data, but the action changes the data.

Today, we also look at the bound action and unbound action, in fact, they call the same way and function is the same, just here is the request to submit a lot of other is the way to use post. Let's first look at two examples:

Public variables

static string clientId = "580C20BE-5960-42A0-837F-9B554B88B2D5";//"025220cd-a8c9-414f-aad7-a9288404262b";         static string service = "https://ghostbear.crm6.dynamics.com";         static string RedirectURL = "Http://localhost/weapidemo";         static string username = "Account";         static string password = "pwd";         static string Webapiurl = "https://ghostbear.api.crm6.dynamics.com/api/data/v8.0";  

Bound Action

It can also be called based on a detailed context, but before calling this bound action, do not forget to add the prefix "Microsoft.Dynamics.CRM", otherwise. The request will fail. In the example below, we added a phone record to the queue. The meticulous friend must have realized that we need to construct the request body here. For the data structure of the request body, it is possible to look at the previous article of the blogger in this new set of APIs. Data structures are simplified, and we are able to construct the request body using the most basic structure.

            Httprequestmessage addtoqueuereq = new Httprequestmessage (httpmethod.post, Webapiurl + "/queues (70f6a997-71bb-            E511-80D8-C4346BC5F7C8)/microsoft.dynamics.crm.addtoqueue "); AddToQueueReq.Headers.Authorization = new Authenticationheadervalue ("Bearer", auth. Acquiretoken ().            Accesstoken);            Jobject addtoqueueactivity = new Jobject ();            Addtoqueueactivity.add ("ActivityID", "3040f58a-75bb-e511-80d9-c4346bc43f3c");            Addtoqueueactivity.add ("@odata. Type", "Microsoft.Dynamics.CRM.phonecall");            Jobject addtoqueuecontent = new Jobject ();            Addtoqueuecontent.add ("Target", addtoqueueactivity); Addtoqueuereq.content = new Stringcontent (Jsonconvert.serializeobject (addtoqueuecontent), Encoding.UTF8, "            Application/json "); Httpresponsemessage Addtoqueueresp = await client.            SendAsync (Addtoqueuereq); if (addtoqueueresp.issuccessstatuscode) {jobject result = Jsonconvert.deserializeobjEct<jobject> (await AddToQueueResp.Content.ReadAsStringAsync ());            Console.WriteLine (result["Queueitemid"]); }

Unbound Action

As the name implies, the action can be invoked on any entity and can be called separately, such as the following example.

Here we call the winopportunity action, which initiates a win order for an opportunity. During. We need to construct the correct request body.

            Httprequestmessage winoppreq = new Httprequestmessage (httpmethod.post, Webapiurl + "/winopportunity"); WinOppReq.Headers.Authorization = new Authenticationheadervalue ("Bearer", auth. Acquiretoken ().            Accesstoken);            Jobject Closeoppitem = new Jobject ();            Closeoppitem.add ("Subject", "Won opportunity!");            Closeoppitem.add ("[email protected]", Webapiurl + "/opportunities (1440f58a-75bb-e511-80d9-c4346bc43f3c)");            Jobject requestbody = new Jobject ();            Requestbody.add ("Status", 3);            Requestbody.add ("Opportunityclose", Closeoppitem);            Winoppreq.content = new Stringcontent (Jsonconvert.serializeobject (requestbody), Encoding.UTF8, "Application/json"); Httpresponsemessage Winoppresp = await client.            SendAsync (Winoppreq); if (winoppresp.issuccessstatuscode) {jobject result = jsonconvert.deserializeobject<jobject& gt; (await WinOppResp.Content.ReadAsStringAsyNC ());            Console.WriteLine (result); }

It is very convenient to call these actions, just to construct the URL and the request body, it is very convenient to call these requests on the light client. At least we don't have to grab the packet and splice the SOAP message body.


Dynamics CRM 2015/2016 Web api:unbound action and Bound action

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.