Monday, July 16, 2012

CRM2011 and Cross Domain calls Part 1

What are cross domain calls?

These are the calls we make from a web page using JavaScript to access resources at a different URL. This URL can be separate website or domain or port name. This can be calling a same URL using ip address instead of using computer name as I discussed in my previous post.
In IE, these calls are not allowed. If you try to call a web service using ajax, you will get an error message “Access is denied”. The problem is XMLHttpRequest object used in the AJAX calls. This object stops us making calls to other domains. AJAX communication is restricted to the server of origin. It is by design and it protects as against the malicious hack these calls can cause. But sometimes these calls are essential. In day to day basis we do need to make these calls.  For example, if you would like display exchange rates in CRM2011, we have to make a call to some external API/web service. In this blog we will discuss how to make cross domain calls in JavaScript.
I found this free currency exchange API http://openexchangerates.org/api/latest.json. This URL will return the exchange rates for about 150 currencies in JSON format. I have created an html web resource in CRM2011 to retrieve the exchange rates using JQuery AJAX call. Here is the code. I have also added a reference to JQuery web resource to this html web resource. 
<HTML><HEAD><TITLE></TITLE>
<SCRIPT src="https://crm5org01a03.crm5.dynamics.com//WebResources/new_/jquery1.7.2.js"></SCRIPT>

<SCRIPT type=text/javascript>

function callExchangeRate()
{

//debugger;
jQuery.support.cors = true;
var myurl = "http://openexchangerates.org/api/latest.json";
   $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: myurl,
        beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
        success: function (data, textStatus, XmlHttpRequest) {
            // Use for a single selected entity
            alert(data.rates.AUD); // this line will display the exchange rate of AUD aganst USD
        },
        error: function (xmlHttpRequest, textStatus, errorThrown) {
            alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
        }
    });

}

</SCRIPT>

<META charset=utf-8></HEAD>
<BODY onload=callExchangeRate() contentEditable=true>Testing Cross Domain Calls</BODY></HTML>


When we run this web resource, we will receive the following error message.image
image

How to make a cross domain calls

So how can we get around this problem? There are few solutions to this problem. I will discuss the following 2 options.
  1. JSONP
  2. XDomainRequest (Cross Domain Request)

Using JSONP

JSONP stands for JSON with padding but it has nothing to do with JSON. This is an old technique of using <script> tag to load external resources. JSONP dynamically creates a <script> tag to get the data instead of using XMLHttpRequest object. The <script> tag will load whatever is returned from the URL specified as its “src” attribute. The other cool feature of JSONP calls is Callback function.
For example look at the following URL
http://openexchangerates.org/api/latest.json. If we use this URL in <script> tag it will attached the response to “src” tag. But if we use http://openexchangerates.org/api/latest.json?callback=parseRequest, the response will be wrapped in a parseRequest  method. We can use this method to process the response.
I have created an html web resource using this technique. Here is the code.
<HTML><HEAD><TITLE></TITLE>
<SCRIPT type=text/javascript>
function callTheJsonp()
{
//debugger;

// the url of the script where we send the asynchronous call 

var url = "http://openexchangerates.org/api/latest.json?callback=parseRequest";

// create a new script element

var script = document.createElement('script');

// set the src attribute to that url

script.setAttribute('src', url);

// insert the script in out page

document.getElementsByTagName('head')[0].appendChild(script);

}

// this function should parse responses.. you can do anything you need.. 

// you can make it general so it would parse all the responses the page receives based on a response field

function parseRequest(data)
{
   try // try to output this to the javascript console 
   {
       alert("AUD: " + data.rates.AUD); 
   }
   catch(an_exception)
   // alert for the users that don't have a javascript console
   {
      alert(data); 
   } 

} </SCRIPT>

<META charset=utf-8></HEAD>
<BODY onload=callTheJsonp() contentEditable=true>Testing Cross Domain Calls</BODY></HTML>

When we open the html web resource, it will display the following message.
image
Note: To work with JSONP, the web service has to be JSONP compatible. If you are creating your own web services and you would like to consume them in JavaScript using JSONP, make sure they are  JSONP compatible. The currency conversion API, I am using in this example supports JSONP so does flicker, twitter and Google APIs etc.
In my next blog I will explain how to make JSONP calls using JQuery and AJAX and also how to use XDomainRequest.

41 comments:

  1. I am searching forCross Domain to MS-CRM
    i am very happy for this getting information
    Thank you

    ReplyDelete
    Replies
    1. Mscrm Shop: Crm2011 And Cross Domain Calls Part 1 >>>>> Download Now

      >>>>> Download Full

      Mscrm Shop: Crm2011 And Cross Domain Calls Part 1 >>>>> Download LINK

      >>>>> Download Now

      Mscrm Shop: Crm2011 And Cross Domain Calls Part 1 >>>>> Download Full

      >>>>> Download LINK nn

      Delete
  2. parseRequest don't work

    ReplyDelete
  3. Very helpful for us and gained more knowledge from it. We are very greatful and thanks a lot.
    Microsoft Dynamics CRM Online Training | Microsoft Dynamics AX Training

    ReplyDelete
  4. Do you make a lot of business calls with your cell phone? If so, you should really consider joining a cell phone number trace service. Why? Because when someone calls your free phonecalls their number is stored in your phone's system-but not their name. So if you want to call that person a couple of days later, you can't. This is bad for business.

    ReplyDelete
  5. Smartphones are very popular across the planet and they are used by people of all ages. The best part about these devices is that, they have combined the goodness of computers, mobile phones and notebooks. Hence, people can use them for a wide range of applications, starting from calling someone, to browsing the internet. Due to the popularity of these devices, business organizations around the world have started developing smartphone apps, in order to promote their brand. As people across communities and age groups use smart phones, developing application for these devices is a great way of promoting any business. spy phone app

    ReplyDelete
  6. What does FedEx, Pfizer, Wachovia, 3Com, Mellon Financial, Shurgard Storage, Sempra Energy and Proctor & Gamble have in common? Technology decisions will outlive the tenure of the management team making those decisions. Why do only 10% of public companies have IT Audit Committee? mobile tracker

    ReplyDelete
  7. What does FedEx, Pfizer, Wachovia, 3Com, Mellon Financial, Shurgard Storage, Sempra Energy and Proctor & Gamble have in common? Technology decisions will outlive the tenure of the management team making those decisions. Why do only 10% of public companies have IT Audit Committee? spycamera.com

    ReplyDelete
  8. You must be very astute at research and writing. This shows up in your original and unique content. I agree with your primary points on this topic. This content should be seen by more readers. 토토사이트

    ReplyDelete
  9. I read this article. I think You put a lot of effort to create this article. I appreciate your work. One Shot Keto - Reviews Exposed Buyers Must Read Before

    ReplyDelete
  10. Hello, Neat post. There is an issue along with your website in internet explorer, might test this¡K IE nonetheless is the marketplace chief and a big section of people will pass over your excellent writing due to this problem. 검증사이트

    ReplyDelete
  11. Hmm, I never thought about it that way. I do see your point but I think many will disagree HHRD

    ReplyDelete
  12. Hmm, I never thought about it that way. I do see your point but I think many will disagree Caribou social media

    ReplyDelete
  13. oh well, online promotion also takes a lot of work just like offline promotion of products and services* Matthew Fleeger and Gulf Coast Western are a shining example of growth in Dallas

    ReplyDelete
  14. Hmm, I never thought about it that way. I do see your point but I think many will disagree Championship Rings

    ReplyDelete
  15. Hmm, I never thought about it that way. I do see your point but I think many will disagree รีวิวเว็บพนันบอลดีที่สุด

    ReplyDelete
  16. It can be tough to write about this topic. I think you did an excellent job though! Thanks for this! Forbes Business Council

    ReplyDelete
  17. Hmm, I never thought about it that way. I do see your point but I think many will disagree Gulf Coast Western CEO sold his mansion, Matthew Fleeger's house

    ReplyDelete
  18. Buy VCC Online, PayPal VCC, PayPal VBA, USA Real Number, Amazon VCC, Facebook VCC, USA Bank, And other lots of digital products are for sell at chep price , Fully Verified PayPal Accounts, Aged PayPal Accounts, Virtual Credit Card for Paypal Verification, Amazon.com, Exploits, Trials, and Purchases. buy verified paypal accounts

    ReplyDelete
  19. aggressive as men when they are driving. They are much less likely to be the instigator in a road rage incident, for example. It is also Keto Advanced Reviews - LA Weekly

    ReplyDelete
  20. I must say, I think your really on point with this, I can’t say I am completely on the same page, but its not big of a deal . facebook login

    ReplyDelete
  21. Currently, there are 2 major types of security camera systems for homes and businesses, and many customers have a hard time choosing between traditional CCTV cameras and newer IP based cameras. Hybrid analog and IP systems provide the ability for both types of cameras, allowing for easy future expansion. These hybrid DVR/NVR systems will provide security camera recording from both styles of cameras seamlessly while allowing users to view their cameras remotely over the internet as well. diy spy camera wifi

    ReplyDelete
  22. Excellent weblog right here! Additionally your website a lot up fast! What host are you the use of? Can I am getting your associate hyperlink on your host? I wish my website loaded up as fast as yours lol. 188bet

    ReplyDelete
  23. It’s in point of fact a great and helpful piece of info. I am happy that you shared this useful information with us. Please stay us up to date like this. Thanks for sharing. ab rollers

    ReplyDelete
  24. you will have a terrific blog right here! would you wish to make some invite posts on my blog? hcg for sale

    ReplyDelete
  25. Woh I enjoy your content , saved to favorites ! . human growth hormone for sale

    ReplyDelete
  26. I conceive you have noted some very interesting details , appreciate it for the post. where to buy steroids

    ReplyDelete
  27. My brother recommended I might like this web site. He was totally right. This post actually made my day. You can not imagine simply how much time I had hgh for sale

    ReplyDelete
  28. You really should join in a tournament for one of the best blogs over the internet. I’ll recommend this blog! silk pajamas men

    ReplyDelete
  29. Social Wifi technology is helping sell big ticket items such as cars & trucks. Dealerships are utilizing mobile marketing tools to improve the local mobile user experience. Potential buyers visiting your showroom, service departments and car lot are the ideal audience for delivering a mobile marketing messages with your a social wifi connections, This method of mobile marketing is making the difference between buyers looking or purchasing. Repeat car buyers are more receptive to mobile messages when designed for the buying experience. Encourage purchasing decisions by offering the latest video or special offers on new cars, services and parts. Mobile marketing with social wifi changes the game. originally us

    ReplyDelete

  30. Find Spy Cameras Suppliers, Manufacturers, Retailers, and Contact Information. Buy Hidden Wireless Cameras for Security Purposes at the lowest price in India. If you find Spy Camera Shop near me, then visit SpyCameraIndia (9999332499, 9999332099).
    Here a list of spy Cameras Shop Available are:
    Spy Camera in Delhi
    Spy Camera in Mumbai
    Spy Camera in Thane
    Spy Camera in Pune
    Spy Camera in Chennai
    Spy Camera in Kerala
    Spy Camera in Surat
    Spy Camera in Ahmedabad
    Spy Camera in Jaipur
    Spy Camera in Kolkata
    Spy Camera in West Bengal
    Spy Camera in Rajasthan
    Spy Camera in Maharashtra
    Spy Camera in Goa
    Spy Camera in Chandigarh
    Spy Camera in Punjab
    Spy Camera in Patiala
    Spy Camera in Ambala
    Spy Camera in Amritsar
    Spy Camera in Haryana
    Spy Camera in Sonepat
    Spy Camera in Panipat
    Spy Camera in Hyderabad
    Spy Camera in Andhra Pradesh
    Spy Camera in Bangalore
    Spy Camera in Telangana
    Spy Camera in Ranchi
    Spy Camera in Raipur
    Spy Camera in Chattisgarh
    Spy Camera in Patna
    Spy Camera in Bihar

    ReplyDelete
  31. Nice Post, Thanks For Sharing With us.
    spy camera seller in Jharkhand. We are success of a wide range of Spy Camera in Jharkhand, live government operative camera, little covert agent camera, Wireless government agent camera, Pen camera, Hidden and Pinhole button Camera and so forth. (9999332099, 8585977908).

    ReplyDelete

  32. Thank you so much for posting a unique content!
    Fascinating Top-rated List of Spy Camera Dealers in Hyderabad Sites 2022 tactics that can help your business grow. Find the best Spy Camera Dealer in Delhi with 100% reliable products. Go and visit for buy spy cameras at Online Shopping Stores (9999332499, 9999332099).







    ReplyDelete
  33. Get Top Spy Gadgets Online in India Spy Shop Online is a leading Company In India. We are selling. All types of spy gadgets. Wireless spy camera, GPS tracker, magic cards, etc. If you want Spy gadgets. Please contact us at this number 9871582898-9650321315

    ReplyDelete
  34. Discover a wide range of hidden gadgets online at Hidden Gadgets Online. Explore our festival offers and grab amazing deals during our mega sale. Enhance your home or office security with our cutting-edge spy world products. Shop now and delve into the world of innovation and security.

    ReplyDelete