Friday, December 27, 2013

WCF: Contracts an Introduction

In WCF all services expose contracts. Now a question arises what is a contract?
 
Contract is a platform neutral and standard way of describing what the service does. There are four types of contracts,
  • Service Contracts
  • Data Contracts
  • Fault Contracts
  • Message Contracts
Here we will try to define and use of each contract type.
 
Service Contracts describe which operations the client can perform on the service.
 
Data Contracts define which data types are passed to and from the service. WCF defines implicit contracts for built in types int and string, but we can easily define explicit  opt-in data contracts for custom types.
 
Fault Contracts define which errors are raised by the service and how the service handles and propagates errors to its clients.
 
Message Contracts allow services to interact directly with messages.
 
We will look into each of these Contracts in later blogs.

WCF : Addresses an Introduction

Every WCF service is associated with an address which will be used by the client to access the service. A WCF address provides two important elements,
  • Location of the service
  • Transport Protocol
Location service indicates that the name of the target machine, site or network; a communication port, pipe or queue and an optional specific path, or URI
 
Transport Protocol also called as Transport Schema is used to communicate with the service. Normally WCF supports below transport schemas
  • HTTP or HTTPS
  • TCP
  • IPC
  • Peer Network
  • MSMQ
  • Service Bus
Normally addresses have the below format,
[base address]/[optional port]
 
At the same time the base address has the format,
[transport]://[machine name or domain][:optional port]
 
HTTP addresses uses the http for transport and can also use HTTPS for secure transport. Typically uses http addresses with outward facing internet based services and we can specify a port also. If a specific port is not provided it will take the default port. For HTTP it is 80 and for HTTPS it would be 443. A sample http address is as follows,
 
TCP addresses uses net.tcp for transport and typically include a port number. If the port number is not provided the default for the tcp address is 808. A sample tcp address is as follows,
net.tcp://localhost:8002/MyService
 
IPC Addresses or Inter Process Communication addresses use net.pipe for transport, to indicate the use of the Windows named pipe mechanism. In WCF, services that use IPC can only accept calls from the same machine. So we have to either provide the machine name or the localhost followed by a unique string for the pipe name. It is not possible for two named pipe addresses to share a pipe name on the same machine because we can open a named pipe only once per machine. A sample IPC address is as follows,
net.pipe://localhost/MyPipe
 
MSMQ or Microsoft Message Queue addresses use net.msmq for transport. We must specify the queue name. If the queue is private we must provide the queue type as well. Samples for the MSMQ is as follows,
net.msmq://localhost/private/MyService
net.msmq://localhost/MyService
 
Windows Azure AppFabric Service Bus addresses use sb, http or https for transport and must include the service bus address along with the service namespace.
sb://MyNamespace.servicebus.windows.net/
 
Now you must have got an overall idea on different types of addresses used in WCF.

Saturday, December 21, 2013

CRM 2011 - Using Report Control to add a report to Dashboard

There can be scenarios where we have to create custom reports to the dashboards. This can be achieved easily using the custom tool Report Control. Download the report control solution from here.
 
Import the solution to our organization.
 
Now keep the report ready in our organization either by creating a new report or by reusing an existing report.
 
Get the report's GUID from CRM which needs to be added to the dashboard. Keep that handy for further use.
 
Whether you are planning to create a new dashboard or an existing dash board, add a new web resource to the dashboard.
 
In the properties window, add the web resource "new_ReportControl". Give proper field name and properties for the web resource.
 
If "Restrict cross frame scripting where supported" and "Pass record object type and unique identifier as parameters" check boxes are checked, then uncheck them.
 
In the custom parameters field, add the GUID value for the report to be added.
 
Full article can be read here. There is another approach for this same objective but it didn't work for me though. You can read the article here.
 
That's it we are done with the new report in our dash board.
 
Hope this helps !!!

Tuesday, December 3, 2013

Windows - How to delete a service which is no longer used?

There can be scenarios where we have some services in the server which is no longer used. In such a scenario its better to delete the same.

For that what you can do is,
  1. Open the command prompt as administrator.
  2. Type the command sc delete <service name>
  3. Enter
The service is deleted from the list.

There are other options to do the same. But the above one helped me to delete the same. If you need to go for other options for any reasons please check here.

Hope this helped you.

Monday, November 25, 2013

CRM 2011 - Script loading to Client

What I understood was wrong from UR12 for CRM 2011. JScripts mentioned in the forms in a specific order was not loaded to the client in the same order. Its loaded in the order in which the same is received from the server.

There is no guarantee that the dependent scripts mentioned in the form may be loaded after the script which is calling the same.

Thanks scott for this wonderful post.

CRM 2011 - Hide the footer from notes in different entities

Different entities have the notes in the form where the user can add, delete notes and also attach files. If the users are not giving proper titles for these notes then we could see that when notes are created there will be redundant data in the title and footer of the note, which is the name of the owner and the date when the note was created.
 
This can be fixed, if required in two ways one way is to educate the users to give a proper title so that the redundant data can be removed. Second way is to hide the footer where the same data is displayed again.
 
Second way is not a supported way in CRM 2011. But we can do this. This has some disadvantages though.
 
This can be implemented only (as per my knowledge, please let me know otherwise) when the form loads as the notes attribute cannot be modified or we cannot add any on change event for the same attribute. Because of which when the user adds a new note the footer will be visible for the new note and when the user deletes an existing note then all the hidden rows will be visible again. This will last until the form is reloaded so that our code is triggered.
 
Below is the code which I used to hide the row
 
function HideNotesFooter() {
//Get the iframe which has the table row which needs to be hided.
var iframe = window.document.getElementById('notescontrol');
//Get the inner document from the iframe object.
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
//Get the list of all elements inside the iframe having the class name 'noteHeader'
var noteHeader = innerDoc.getElementsByClassName('noteHeader');
//Checks whether the noteheader contains any element or not. If it doesnt have any element trigger this function after sometime.
if (noteHeader.length == 0) {
setTimeout(DisableNotes, 1000);
} //End if for length
else { //If it has any element loop through them and hide the respective row from the table.
for (i = 0; i < noteHeader.length; i++) {
if (i % 2 != 0) {
noteHeader[i].style.visibility = 'hidden';
} //End if for modulus
} //End for loop
} //End else
} //Function End
 
I have used a call to the setTimeout function because some time I could see that the rows to be hided were not available when the script execution was happening.
 
Hope this helped you.

Tuesday, November 5, 2013

JavaScript Errors

When our script attempts to perform an action that the system cannot execute a run time error occurs. It will be easy if we can identify the same from the number returned so that a meaningful user friendly message can be passed on to the end user.
Similar is the case for the syntax errors.
Below is the link to msdn site which will give a fair idea on these error numbers and the description.
For Runtime error check here.
For Syntax errors check here.

Configuration for CRM Plugins

CRM plugins are always great feature where we can automate many functionality which we cannot automate from user interface. But almost eve...