Calling WCF Rest Service from a Plugin in CRM 2011 (Online)

Let us take a simple rest service example here

It returns the string “You have asked for photos”.

Within the plugin class add references to following assemblies.

The sample code of the plugin

namespace TestPlugin
 public class Class1 : IPlugin
 public void Execute(IServiceProvider serviceProvider)
 IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

 if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

// using WebClient
 WebClient webClient1 = new WebClient();
 string data1 = webClient1.DownloadString("");

// using WebChannelFactory
 WebChannelFactory<IPhotos> factory = new WebChannelFactory<IPhotos>(new Uri(""));
 IPhotos proxy = factory.CreateChannel();
 string photos = proxy.GetPhotos();



 public interface IPhotos
 [WebGet(UriTemplate = "Photos")]
 string GetPhotos();

Register the plugin in Sandbox mode for CRM 2011 online.

Check this wonderful post for all the details

Hope it helps.

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.