Advertisements

Archive

Posts Tagged ‘SOAP’

Using CRM 2011 SOAP and REST endpoints with Silverlight

February 27, 2013 Leave a comment

To communicate with CRM 2011 from Silverlight application you can either use SOAP or REST endpoints.

URL’s for both endpoints will be available under “Developer Resources” section (Go to Settings -> Customizations -> Developer Resources)

SOAP and REST endpoints

SOAP and REST endpoints

Below are the important points on usage & limitations of both endpoints

Using REST endpoint with Silverlight

  • CRM 2011 uses the WCF Data Services framework to provide an OData endpoint that is a REST-based data service.
  • This endpoint is called the Organization Data Service
  • It supports early bound entity types so that the coding will be easy (i.e., you can instantiate contact c=new contact(); c.name=”Rajeev”)
  • Limitations
    • Only Create, Retrieve, Update, and Delete actions can be performed on entity records
    • You need to regenerate the proxy every time you change the entity schema (Ex – If you create a new entity or attribute)
    • You cannot use late binding to work with custom entities that were not included when proxy generated.
    • Here is the MSDN article Walkthrough REST in Silverlight

Using SOAP endpoint with Silverlight

🙂

Advertisements

Assign record using JScript in CRM 2011

February 4, 2012 7 comments

Hi,

Below is the Jscript to assign a record to particular User using SOAP.

function AssignRecord(Assignee, Target, entityName) {

var request = “<s:Envelope xmlns:s=\”http://schemas.xmlsoap.org/soap/envelope/\”>”;

request += “<s:Body>”;

request += “<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\””;

request += ” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;

request += “<request i:type=\”b:AssignRequest\””;

request += ” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\””;

request += ” xmlns:b=\”http://schemas.microsoft.com/crm/2011/Contracts\”>”;

request += “<a:Parameters xmlns:c=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;

request += “<a:KeyValuePairOfstringanyType>”;

request += “<c:key>Target</c:key>”;

request += “<c:value i:type=\”a:EntityReference\”>”;

request += “<a:Id>” + Target + “</a:Id>”;

request += “<a:LogicalName>” + entityName + “</a:LogicalName>”;

request += “<a:Name i:nil=\”true\” />”;

request += “</c:value>”;

request += “</a:KeyValuePairOfstringanyType>”;

request += “<a:KeyValuePairOfstringanyType>”;

request += “<c:key>Assignee</c:key>”;

request += “<c:value i:type=\”a:EntityReference\”>”;

request += “<a:Id>” + Assignee + “</a:Id>”;

request += “<a:LogicalName>systemuser</a:LogicalName>”;

request += “<a:Name i:nil=\”true\” />”;

request += “</c:value>”;

request += “</a:KeyValuePairOfstringanyType>”;

request += “</a:Parameters>”;

request += “<a:RequestId i:nil=\”true\” />”;

request += “<a:RequestName>Assign</a:RequestName>”;

request += “</request>”;

request += “</Execute>”;

request += “</s:Body>”;

request += “</s:Envelope>”;

// Get server URL

var serverUrl = Xrm.Page.context.getServerUrl();

var req = new XMLHttpRequest();

req.open(“POST”, serverUrl, true)

// Responses will return XML. It isn’t possible to return JSON.

req.setRequestHeader(“Accept”, “application/xml, text/xml, */*”);

req.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

req.setRequestHeader(“SOAPAction”, “http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute&#8221;);

req.onreadystatechange = function () { assignResponse(req); };

req.send(request);

}

// This function gets called after the execution

function assignResponse(req) {

if (req.readyState == 4) {

if (req.status == 200) {

alert(“Success !!!”);

}

else {

alert(“Error – ” + req.responseXML);

}

}

}

How Do I Call this function :-

  • Pass User Id, Record Id and Entity name to the function

var userId = “”      // GUID of user whome to assign the record

var recordId = “”      // GUID of record you want to assign

var entityName = “”  // Entity name the record

AssignRecord(userId,recordId,entityName);

Hope it helps 🙂