Friday, October 30, 2015

CRM SOAP Library- Part 3 (Testing CRM web resources for CRM Online in Visual Studio)

This is a part 3 of the CRM Soap Library series. This blog covers how to test the web resources that make CRM web services calls  from visual studio for MSCRM Online.

If you run the CRM soap library sample or "StartUp.htm" page from my last blog CRM SOAP Library - Part 2 (Project Structure) , you will get the following  error.

“Sdk.Util.getClientUrl Unable to get clientUrl. Context not available.”

This is a straight forward error. The library is trying to get the CRM URL from global context or Xrm.page.Context. For development purposes,  you can replace the “GetGlobalContext().getClientUrl()” line in “Sdk.Soap.min.js” with your  CRM Online URL.


Now if you try to run the code after making the change,  code will throw the following error.

“status: 401: Unauthorized”

It becomes a pain when you have to keep deploying Java Script resources to CRM to test them. There are hundreds of forums/blogs that talk about this problem but you can’t not see any solution.

I figured out a way around this problem with the help of “Fiddler”.So, here is hack that will allow you to run/test you web resources without deploying them in CRM.

Here is the step by step tutorial to achieve this.
  1. If you don't have fiddler installed already, install it.you can download it from http://www.telerik.com/download/fiddler.
  2. Start the fiddler and make sure “Capture Traffic” is selected  in the “File” menu as shown in the screen shot below.
     image
  3. Logon to your CRM organisation. I am using CRM Online for this tutorial.
  4. Switch to fiddler and double click on  a CRM URL from the session pane as shown in the screen shot.
    image
  5. In the second pane, select “Inspectors>>Cookies” as shown in the screen shot below. if the contents of cookies for the selected request does not look the same try some other URL from the session list.
    image
  6. Look for “MSISAuth” in the contents and select everything from that text onwards and paste it notepad.
  7. Select “Tools>>Customize Rules” as shown in the screen shot below. It will open the “CustomRules.js” file.
    image
  8. Search for  “OnBeforeRequest(oSession: Session) function in the file and add the following code to it.

    1:  if (oSession.PathAndQuery=="/XRMServices/2011/Organization.svc/web")  
    2:   {  
    3:               //appending the cookie data for the request  
    4:            oSession.oRequest["Cookie"] = (oSession.oRequest["Cookie"] + "; text copied in step 6" );  
    5:  }  
    
    

  9. Replace the highlighted text with the text copied in step 6. Save the changes to the file.
  10. Open up your HTML page in VS and test it. You won’t get the unauthorised error  anymore.

6 comments:

  1. I am not getting mentioned error (“Sdk.Util.getClientUrl Unable to get clientUrl. Context not available.”) but instead i get
    1.Starting 'Early Binding' Sample
    2.Starting sample by creating account.
    3.Error on Create accountError: status: 0:

    ReplyDelete
  2. Hello, thanks for taking the time to view my profile. I am an academic writer from the US who enjoys finding new topics to research and write about.
    Medical Assignment Help

    ReplyDelete
  3. Good way of telling, good post to take facts regarding my presentation subject matter, which i am going to deliver in my college
    Matlab Symbolic Math Help

    ReplyDelete
  4. I appreciate your efforts in preparing this post. I really like your blog articles.
    SPSS Factor Analysis Help

    ReplyDelete
  5. The leading assignment help UK firm offers state of the art services to its clients with a promise of delivering all the required work well within the deadline.
    Science Papers Assignment Help

    ReplyDelete
  6. Things are very open and intensely clear explanation of issues. was truly information. Your website is very beneficial.
    MathCad Online Project Help

    ReplyDelete