Introduction and Notes about WCF, Silverlight and Creating a Silverlight application that consumes – invokes a WCF service via async (asynchronous) web service call

This post is an introduction and a collection of some useful information, notes and facts about WCF in genreal, Silverlight and running a silverlight web application that uses a WCF service via asynchronous web service call.

– The first fact that you need to know is that:

The only option for web service calling in Silverlight is asynchronous and Silverlight framework does not provide any API for synchronous call. Saying that, there are few work arounds for synchronous web service calls from silverlight to a WCF service. Personally, I haven’t tried or need to use any of these. If you are interested, you can look at one of these posts:
 * http://weblogs.asp.net/razan/archive/2010/01/14/emulating-synchronous-web-service-call-in-silverlight.aspx
 * http://marcgravell.blogspot.com/2009/02/async-without-pain.html
 * http://petesbloggerama.blogspot.com/2008/07/omg-silverlight-asynchronous-is-evil.html
– The greatest advantage of calling methods asynchronously is because it enables the application to continue doing useful work while the method call runs. If there is any delay from the WCF service in sending back the required data, Async calls ensures that your client application is not hanging there freezing and doing nothing until the Windows Communication Foundation (WCF) services returns the requried data. WCF and clients can participate in asynchronous operation calls at two distinct and different levels of the application. This makes WCF applications flexibile to maximize throughput balanced against interactivity.

– Visual Studio .NET 2008 gives you two project templates to create a WCF project:
 1- “WCF Service Application” and
 2- “WCF Service Library.”

WCF Service Application is the conventional web service application similar to ASP.NET web service but in this case built on Windows Communication Foudnation technology.

WCF Service Library project is different. The output of this project is a compiled dll file(s) along with a dll.config configuration file. The produced output can then be added to a client service application or project, deployed as a separated secure web service or as part of a larger hosted web service.

– When creating a WCF service for a silverlight application, you can simply add the WCF service to the test Web project which is added by default by Visual Studio when you create a new Silverlight 3 project. You can do this by right clicking on the silverlight web project (test project usually called .Web) and then click on add new item. In the new item window, always choose in this case silverlight enabled WCF service as this adds one line to your web.config. On the other hand, you can add the WCF service as another project to the same solution or even a separate solution which is the more practical approach as normally the web service is separate and hosted independantly from its client(s).

– If the WCF client application is not silverlight, opt to use the asynchronous approach in your operation implementation especially in the case when the service implementation makes a blocking call, such as doing Input/Output IO work.

Generally, even if you have a choice to choose between a synchronous and asynchronous call, always try to opt for the asynchronous one.

MSDN (and Microsoft) specifies the essential cases that you need to use Asynchornous calls to WCF as follows:

* If it is a silverlight application (the only option you have really!).

* If you are invoking operations from a middle-tier application.

* If you are invoking operations within an ASP.NET page, use asynchronous pages.

*- If you are invoking operations from any application that is single threaded, such as Windows Forms or Windows Presentation Foundation (WPF).

In all these cases, always try to opt to Async calls rather than synchronous if this is an option.
– WCF is Microsoft’s attempt of unifying web and distributed services. WCF services can work with a variety of client applications including php, ruby, etc. and any client that can use basicHTTP binding.

– WCF is regarded as the successor to conventional Microsoft web services and communication technologies such as: DDL, DCOM, Remoting, Web Services, WSE, etc.. This is especially because WCF is built with the aim to provide “SOA” or Service Oriented Architecture for distributed applications.

– WCF can have messages sent in a variety of channels including HTTP, TCP, MSMQ, Named pipe, etc.

– WCF runtime resides under the System.ServiceModel namespace.

– In most cases WCF has a much better and faster performance ranging between 25%-50% in some cases. Refer to this MSDN article for some comparisons: http://msdn.microsoft.com/en-us/library/bb310550.aspx

– The throughput of WCF is inherently scalable from a single processor to a quad processor.

– The WCF model unifies the feature wealth of ASMX, WSE, Enterprise Services, MSMQ, and Remoting. This way, developers only have to master a single programming model.

– WCF can be hosted in IIS Servers, Windows services and standalone apps like windows forms, console apps.

– WCF provides a DataContractSerializer which allows complex data types and private attributes to be serialized and sent. Being Serializable means, the object can be hydrated, dehydradted from a stream/bunch of bytes, into a living class instance.

Renaming Left Navigation Menu items (leftnav) of an Entity in Microsoft Dynamics CRM 4

I will try to make this as simple and straight to the point as possible.

This post is to explain how to to change the name and rename one or more of the left menu items – leftnav – items of an Entity, for example the Account entity or the Contact entity or any other Custom entity. In summary, this should be done using a script in the onload event of the entity form and apparently can NOT be done using the Isv.Config file.

So for example, when you open an account record, on the left hand side of the Account form you will have the left navigation list of entities which are: Activites, History, Sub-Accounts, Contacts, Relationshiips, Workflows, Opportunities, Leads, Quotes, Orders, Invoices, cases, contracts, marketing lists and campaigns.

To rename any of these entities or any other custom entity has a 1:N relationship with the Account entity, you will need to put some javascript code (or script really) in the OnLoad event of the Account Form. This code will look for the name of the left navigation item (link to an entity) and rename it to whatever you want. You can not do this in ISV.CONFIG as you can only add new links to ISV.CONFIG but you can not edit already existing left menu items in this file as they don’t exist and are not displayed.

So, in the OnLoad event of the entity that you want to rename its left navigation menu items, you will need to put the fulling code (or something like it):

var navItem = document.getElementById(‘leftNavMenuItemID’);
navItem.innerHTML = navItem.innerHTML.replace(‘>CurrentLinkValue’,’>NewLinkValue’);

This code will look for the menu item that has an id (‘leftNavMenuItemID’) in your chosen entity form and replace its current link name to a new link name.

So for example:

var navItem = document.getElementById(‘navContactsMenuItem’);
navItem.innerHTML = navItem.innerHTML.replace(‘>Contacts’,’>Employees’);

If you input this code in the OnLoad event of the Account entity Form, this code will look for the “Contact” entity link in the left navigation and rename it from Contacts to Employees.

You can apply the same to any other entity either it is a customisable (system) or custom entity. You will need to use a HTML tool such as Microsoft’s Internet Explorer Developer Toolbar to find out the ID of the navigation item that you want to rename (‘navContactsMenuItem’).

Please let me know if you have a question or if you want me to clarify more.

Thanks,

Mohamed Ibrahim

Setting up Microsoft CRM Internet Facing Deployment IFD with Multiple organisations

You can always setup Microsoft Dynamics CRM with Internet Facing deployment IFD either using the IFD tool by Microsoft or using the manual hard coding in the config files. I have recently used the IFD tool to do so and after I managed to get everything sorted, an important question came to mind which is: How can we setup Microsoft Dynamics CRM with Internet Facing deployment and at the same time allowing the external (Internet) access to all the CRM server organisations. So for example, if you have 3 CRM organisations (organizations) and you expose your Dynamics CRM server to external access via the Internet, you will usually have one domain name and one IP address for this server. So www.yourcrmserverdomain.com points to an IP address of 91.91.91.91 and this IP address is the real IP address of your Microsoft Dynamics CRM server. How can you make this point to different organisations all setup on the same server and the same CRM server.

I did search quite a lot on google, I have to say to find the answer as I was away from my server to try it myself one and I could not find a post or an article discussing it. This is probably because it is either too simple for everyone (although it didn’t seem that simple to me) or may be because I am useless in searching using the right keywords.

Anyway, the answer I found was very simple, although it might seem to some people (like me) as a potential issue because you have one server in IIS and you don’t have clear folder categorisation for each organisation to allow you to point different domains to different folders in the same CRM IIS node. Simply all you need to do is to direct the user to the server URL and then follow this with the organisation name.

So to point your external CRM users to organsiation 1, point these external users to go to www.yourcrmserverdomain.com/organisation1. And for example, for Organisation 2, www.yourcrmserverdomain.com/organisation2, and so on.. The default organisation can be accessed directly by using your CRM server URL (for ex: www.yourcrmserverdomain.com) or by the url www.yourcrmserverdomain.com/organisation1 (in case the default organisation is called organisation1). Both will work

Substitute the domain name, organisation 1 and organisation 2 with your actual domain and organisation names.

Please feel free to contact me if you have any questions.

Thanks,

Mohamed

Using the Internet Explorer Developer Toolbar with Microsoft Dynamics CRM

If you ever want to know the name of a html element (html element id) you will most probably need Internet Explorer developer toolbar. IE developer Toolbar is a free Microsoft product that you can download from Microsoft’s download website.

Once you download and install the toolbar, you can view it by clicking at view –> Explorer bar –> IE Developer Toolbar.

From the tool bar viewer, you do a lot of things. One main thing that I personally always need whenever I’m doing a script (javascript) for Microsoft Dynamics CRM is HTML element name, id, innerHTML, innerText and rest of element’s attributes, etc..

After opening the IE developer toolbar, click on find –> select element by click and just go and click on the element you need more information about. You will then get absolutely everything you might need (me thinks!).

I think this is definitely useful in many cases and a lot of JavaScript general coding.

<a href=”http://www.microsoft.com/downloadS/details.aspx?familyid=E59C3964-672D-4511-BB3E-2D5E1DB91038&displaylang=en”>Download the toolbar here<a/>

Error with Report Server

We have been recently approached by a client who had a problem with their report server. If you try to access reports from the reports manager, reports run fine and you can view any report fully and in the right format. The problem arrises when a .NET application tries to open these reports, it just opens a new internet explorer window and uses a url to show the report. This was working fine until the client has probably made some changes to their report server. Since then, reports are not displaying in Internet explorer.

To cut a long story short, we eliminated all authentication issues by checking that security and access to all reports is properly configured and the right users has the right to run these reports. We also eliminated problems between SQL Server and the report server, as reports can run smoothly from the reports manager.

We finally came with the concolusion that the error must be related to Internet Explorer not able to render the report properly. We looked through IIS but could not find anything that looks wrong or not the way it should. I have then checked the security setting of Internet explorer (Tool –> Internet Options –> Advanced) and this all seemed fine but I ticked the box that says display all scripting errors. We also did something which I am not sure if it made any difference, which is that we added the server to the trusted sites in Internet Explorer. Then when we tried to open the report again, this time we started to get scripting errors (although they were not showing in the status bar before for some reason). Scripting error dialogs start to show and we finally started to understand what is happening. We got errors such as: “RS Controller is undefined”, “RSControl object reference not set to an object”. We quickly googled this error and we found an easy and simple solution for this (can’t find the original solution at the moment). The solution is to go to the report server itself, open IIS, right click on your reports server (usually under default website), go to directory –>configuration –> search for axd and double click to open its properties. On there uncheck the filter option (can’t remember the option on top of my head and I don’t have access to any IIS 6.0 at the moment to get the exact option wording). Finally click ok.

This has simply solved the problem, and we managed to get all reports back working from the browser and the .NET applicaiton now opens these reports externally with no issues at all.

I have created this post few days after the resolution, and I don’t have access to the client’s servers at the moment so if you have a similar problem and the post doesn’t answer your questions, please feel free to comment here and I promise I will get back to you as soon as I can with more details and may be a screenshot!

All the best.