Host WCF Service on IIS and Call in Silverlight 2 using ScriptManager
Last post 05-01-2008 2:47 AM by sahil_24. 2 replies.
Sort Posts:
04-29-2008 9:19 AM
Host WCF Service on IIS and Call in Silverlight 2 using ScriptManager
Hi ,I recently have developed a silver light 2 web project to demonstrate the Ajax calling capability of a WCF service from silver light . To do this during the development time I added a new WCF project .svc file in my project which automatically gives me the two code files in my App_Code folder which were having all the code required to build the WCF service . To call this service [ AJAX CALL ] from my silver light client I modified all the desired [ Web service behavior and end point ] setting in my silver light Web.config so that it can be callable and proper binding can be made between my silver light client and WCF client . To register and call this service from client side I then added a Script Manager tag on my page which something looks like as given below .. <asp:ScriptManager ID="ScriptManager1" runat="server"><Services>
 <asp:ServiceReference Path="~/EmployeeService.svc"/></Services>
        <Scripts>
            <asp:ScriptReference Path="~/getEmployeeData.js" />
        </Scripts>  </asp:ScriptManager>
A small section of code from my JavaScript file [ Client side code ]  ..function callService(forUpdatableFields)
{  
  hclpoc.ajax.employee.EmployeeWebService.getUpdatableDetails(ID,UpdtFldsCallBack); 
}
To my delight , it works fine and I was able make a Ajax call . My second step was to host my silver light solution on ISS by configuring a new website . During this step the home directory path of my site was pointed to my silverlight application on my development machine . To this point all thing were working correctly .Now the problem is as in real life scenario Can I host my WCF service and my Silver light application on two different website/virtualdirectory on IIS and then add the WCF reference in my Script manager tag or by doing some other setting and then achieve the desired behavior of calling this WCF service from my client Js code .. How I will accomplish that as currently my silver light client is throwing when I am calling my WCF service from JavaScript .The two URLS on IIS for silver light and WCF are given as following–http://localhost:81/EmployeeDetails.aspxhttp://localhost/EmployeeService.svcIn this scenario my script tag was looking something like this ..<asp:ScriptManager ID="ScriptManager1" runat="server"><Services><asp:ServiceReference Path="http://localhost/EmployeeService.svc"/>        </Services> <Scripts>       <asp:ScriptReference Path="~/getEmployeeData.js" />     </Scripts>  </asp:ScriptManager>My question Is the above solution is possible .. i.e call a WCF service in the same manner as we used to call a webservice from AJAX client .. ??I know that I can create a WCF DLL and then can modified my svc file in my solution to reference this dll instead of  WCF service cs file . and placing this DLL under my solution bin directory . Any other solution/feedback are welcome . I just don’t want to self host this WCF service in silver light app.  
sahil_24

Joined on 04-29-2008
Posts 2
04-30-2008 10:20 PM
Marked as Answer
Re: Host WCF Service on IIS and Call in Silverlight 2 using ScriptManager

Hi:

sahil_24:
The two URLS on IIS for silver light and WCF are given as following–http://localhost:81/EmployeeDetails.aspxhttp://localhost/EmployeeService.svc

  Since you're uisng different port it's cross domain. Please check out this article:

http://msdn2.microsoft.com/en-us/library/cc197955(VS.95).aspx

Regards

Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Allen Chen – MSFT

Joined on 03-16-2007
Posts 717
05-01-2008 2:47 AM
Re: Host WCF Service on IIS and Call in Silverlight 2 using ScriptManager

Thanks a lot . This article and the points suggested by you have really solved my problem .

Just to confirm as cross domain call from Silverlight to WCF was also a constraint in Silverlight 1 or 1.1 .

 Thanks for your time Big Smile

After suggested changes my  Script mamanger tag will look like as following

 <asp:ScriptManager ID="ScriptManager1" runat="server">

<Services>

<asp:ServiceReference Path="http://localhost:81/WCFWebService/EmployeeService.svc" />

</Services>

<Scripts>

<asp:ScriptReference Path="~/getEmployeeData.js" />

</Scripts>

</asp:ScriptManager>

IN above example , Please note readers that my silverlight 2.0 application and WCF are both hosted on port 81 .

Now my Silverlight URL is : http://localhost:81/EmployeeDetails.aspx

And WCF application URL is  : http://localhost:81/WCFWebService/EmployeeService.svc

sahil_24

Joined on 04-29-2008
Posts 2