How to update WCF service reference dynamically in silverlight? - silverlight

How to update WCF service reference dynamically in silverlight ?
Suppose I have created WCF service in my system and added reference to silverlight project, now when I host this on server I want that automatically it takes that system reference .

Take a look at Tim's post:
Managing service references and endpoint configurations for Silverlight applications

Related

Add web project to silverlight application - how to

I have created a WCF Service application, which contains a reference to a service I created.
I want to add this service application as the web component of my SL application, but I can't seem to find the option that allows me to do this.
Can someone help me out here?
Thanks.
I think you need to create a web site, then add a reference to the WCF Service from the website. You could also just have the .svc file in the website. Then right-click on your Silverlight application project and Add Service Reference. This will generate the Reference.cs (show all project files and expand the service reference to see) that will contain all the classes that you exposed in your WCF Service through return or paramaters in your methods.

Service Model in Silverlight

What is the best model for using services in a silverlight application?
I usually add a wcf service to my ASP.net app and add a service reference to my silverlight application, but anytime I change my service I should update the service reference in silverlight app.
Is there any better and more professional way?
If you use WCF RIA Service instead of a plain WCF service, it will automatically be updated whenever something on the service end changes.
If you continue to use plain WCF, you will need to update the service anything you change something.
You can also write your own model and expose them to the silverlight client, just like WCF. Everything is almost the same, except ria services was built for this purpose and more.

deploying services to use SQL server in silverlight

I've made a service for my silverlight 4 database (SQL) affairs (VS2010, C# ASP.NET web app), now I'm writing my SQL functions in this service, how can I use this functions? I've read some articles about deploying services but I think my case should not be much complicated, I have a big ASP.net web app with several web pages (I have a server running on winserver2008), it works great, also I have a SL app, what kind of files should I upload for using service? do I need an asmx? how can I create it? should I change anything in web.config?
what is the easiest way to use my service for communicating between SQL and SL? thanks
WCF RIA Services is the way to go. You do not want to bother with old-school ASMX web-services.
You will use an EF model and a DomainContext on the server to handle all database access via CRUD methods (Create, Read, Update & Delete).
On the client you will use the generated Domain Service client to access data.
Notes from my previous RIA post:
My suggestion is to always create RIA Service libraries instead of adding directly to a Silverlight application. Then you can link the Client-side library to any number of Silverlight applications, then link the .Web part of the RIA library to your website to provide the WCF service. Again the key is to migrate the config settings.
It will probably make a lot more sense if you create a new RIA services library project, add your EDM etc, then link the halves to a separate Silverlight app and your new ASP.net website.
Step-by-step:
Create RIA Services Library project by selecting Add New Project. Select Silverlight on the left. Select WCF RIA Services Class Library on the right. I will assume it is called the default name RIAServicesLibrary1 for this example. It will create a Silverlight client library called RIAServicesLibrary1 and a standard .Net library called RIAServicesLibrary1.Web for use by the Web server.
Add your EDMX to the RiaServices.web project. Select Add new item. Select Data on the left. Select ADO.Net Entity Data Model on the right. I will assume it is called the default Model1.edmx for this example. Connect it to your database tables etc.
Build your project so that the next step will find your data model.
Create a Domain Service referencing your EDMX models in your RiaServices.web project. Select Add new item. Select Web on the left. Select Domain Service Class on the right. I will assume it is called DomainService1.cs for this example. Choose your data items from the Add New Domain Service Class popup window by ticking the checkboxes. A set of RIA services objects and methods will be created for each item you select.
Add a reference to the client Ria services library project (RIAServicesLibrary1) to your Silverlight application.
Add a reference to the web RIA services library project (RIAServicesLibrary1.Web) to your hosting web application (e.g. you ASP.Net website).
Copy/merge the various sections in the RIAServicesLibrary1.Web/app.config file into your <webapplication>/web.config file. This will include any connection strings and the module sections.
Build the project again so that the Data Source window will see your new Domain Context data sources.
Use the RIAServicesLibrary1 client object (called DomainService1 in this example) directly from your Silverlight code like this:
DomainService1 client = new DomainService1();
or use the Data Sources window to drag/drop a new grid etc onto a page.
If the Data Sources window is not visible select the "Data" menu then the "Show Data Sources" option.
For more information try this Microsoft link: Using WCF RIA Services

Silverlight 4 and WCF

I have a WCF service (using HTTP binding) that our WinForm and WFP apps can use with no problem. We have a Silverlight 4 developer who is saying he's not able to use the WCF service because it needs to be "reconfigured" for Silverlight use. I don't know if this is true or not, because I don't know anything about Silverlight.
So, my question is this. Should a WCF service, that uses HTTP binding, that is successfully being used by our WinForms and WPF applications, also be able to be consumed by Silverlight apps, without modifying or reconfiguring the WCF service?
Silverlight 4 supports the following bindings:
BasicHttpBinding
PollingDuplexHttpBinding
CustomBinding (with a subset of binding elements)
Silverlight and WCF Feature Comparison:
There are several ways to use the WCF
client stack to access a service.
It is used when invoking services
through automatically generated
proxies, as described in How to:
Access a Service from Silverlight. The
proxy must be generated in this
procedure by using the Add Service
Reference tool in Visual Studio 2010
for the Silverlight project.
Caution:
Proxies generated by using the WCF
Svcutil.exe tool will not work in
Silverlight 4. Use the SLsvcutil.exe
tool instead. For more information
about using this Silverlight tool, see
Using SLsvcUtil.exe to Access a
Service.
If you already have a Windows
Communication Foundation (WCF) service
contract definition, you can use the
generic ChannelFactory class without
having to generate a proxy. This might
be the case, for example, if your
client is sharing service definition
code with the project on the server.
In this case you could, for example,
define a service contract interface
IStockQuoteService and then use the
same IStockQuoteService code in both
the server and Silverlight projects.
This would involve using a
ChannelFactory.
This advanced technique is
demonstrated in How to: Call
Operations Asynchronously Using a
Channel Factory and in the Silverlight
4 context with Building and Accessing
Duplex Services. For more information
about defining and using service
contracts, see Designing Service
Contracts.

Silverlight RIA Service hosting

I wonder is it possible to host RIA service as a stand alone application in IIS7? I've playing around with some RIA services and a wonder whether this scenario is possible. My goal is to detach the service from the WebSite application and host it separately.
Thanks in advance!
Definitely possible, just create another ASP.Net webforms application, add the domain service, reference your model (if its in another library), and link the Silverlight project to it. Might also be best to host your XAP in the same project as the RIA service to avoid any cross domain issues. In your real website, just copy and paste the object tag and javascript it generates and make sure its pointing to the right location on the RIA service site.

Resources