Home > SharePoint 2010, WCF > Deploy a Custom WCF into SharePoint2010—Part 3

Deploy a Custom WCF into SharePoint2010—Part 3

Deploy a Custom WCF into SharePoint2010—Part 1

Deploy a Custom WCF into SharePoint2010—Part 2

Deploy a Custom WCF into SharePoint2010—Part 3

Deploy a Custom WCF into SharePoint2010—Part 4

In the first 2 parts of this series, I showed you how to deploy custom WCF deploy into SharePoint and consume such WCF in a console application. In this post I would like to show you how to consume the same WCF service in a Silverlight application. You can download the source code here

1. Create Silverlight application and add the WCF references as below. (I know I told you it is not a good practice to consume WCF in this way when you have control over both WCF server side and client side and both server and client side are written using .net, it is a little bit harder to consume the WCF services in Silverlight in this way as you cannot add non-Silverlight class assembly to the Silverlight project.).

2. Add 2 labels controls and one button control to the form and add the following code to the button click event.

3. Deploy the Silverlight into SharePoint by creating SharePoint module item template and add the Silverlight to a sitepage. For details of the configuration, check my previous blog post here.

4. Once deploying the solution to the SharePoint2010, navigate to http://ybbest/sitepages/HelloWorldSL.aspxthen click the “click me” button, you will get the results as follow.

Advertisements
Categories: SharePoint 2010, WCF
  1. Michael
    September 2, 2011 at 6:58 am

    Hi,

    I’m also trying to deploy a custom service in SharePoint but no matter what I am doing, I cannot get rid of the cross-domain policy error. It works when I use another non silverlight client tho.

    I’ve spent hours searching online for examples that are using Silverlight clients but yours is the only one I’ve found. Despite it all, I am still getting this error. I’ve then gone ahead and used your example and changed the WCF calls a little to only return strings and not have any SharePoint.dll references (for testing of course) so that I can literally have ‘Hello world’ returned.

    The scenarios I’ve tested are both running it from within and outside of SharePoint context using an anonymous site and whatnot.

    I’ve also dumped crossdomain.xml and clientaccesspolicy.xml files in the root of the SharePoint site as well as in the ISAPI folder where the customservice.svc file resides…still no luck.

    Have you had this issue when you developed your example?

    Any help would be greatly appreciated!

    Thanks
    Mike

    • ybbest
      September 3, 2011 at 1:57 pm

      Hi Mike
      In my example , I am using relative URL to create service end- point.Therefore , it is not cross-domain.If you are consuming the services within SharePoint in this way, you should not have the problem.If you are consuming WCF using Silverlight and make cross domain call ,putting clientaccesspolicy.xml in the root of the site should be OK. Do you want to send me your code example so that I can have a look?
      Regards
      Ben

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: