I am using prism and have a number of modules. In several of them I am making webservice and wcf calls. I want to be able to configure the information about these services in one place. Should I do this in a resources.resx file? I remember a settings.setting file but that was in a web application.
JD
You can put it in the app.config or you can follow this blog on passing server information to the Silverlight client.
Silverlight Bits&Pieces has this piece on Silverlight configuration options.
When you create service reference in a Silverlight Application, it should automatically generate a ServiceReferences.ClientConfig XML file and put it in your project. It will put the binding and endpoint config info in this file. If you create an instance of your service proxy object without specifying any binding/endpoint it will use the info from the file.
What you can do is the following:
In the Bootstrapper application, add a reference to that WCF
Create your own custom proxy class imlpementing an interface that dictates the methods to be called
Register this IProxy with Unity Container, then pass to each of your ViewModels an IProxy parameter. Unity will do the job by injecting the real instance of that IProxy.
This way you have based all the WCF connection in one place.
Does it help?
Regards
Related
Currently I am working on an ERP Project, Using Entity FrameWork and WCF at server side and WPF at client side. Since it is a big project , we have a lot of entities.What we did so far is, Created Service contracts for each Entities and exposed with multiple endpoints.The Problem is we had to add Service Reference for each Service and we are feeling difficult to manage these web services.
1.Is this a proper way ?
if yes,
2.Is there any way to allocate these web services (in classes or folders)..?
Thanks in advance.
You don't want to keep generating the proxy classes in the client.
Just move the POCO classes and contracts to single assembly which you can reference in the server and client. Then create the necessary channels in the client with ChannelFactory.
ChannelFactory(TChannel)
If you are dealing with many services you can create routing service which will behave like facade. Once you have routing service defined then all requests are going to be sent towards routing service and then, based on some criteria, provided to specific service. You are dealing with only one service so if any change in sub-services occures, for instance endpoint's address is altered, then such a change needs to be reflected only in routing service.
Finally i got how to deal with multiple Services
i am considering to use svcutil.exe in order to create proxy classes.
so that we can arrange those classes in folders, and also we can
get more control over proxies
I am hosting a WCF service on a server, and I want to consume the service from my WPF application. My WPF application is written in the MVVM design pattern in two assemblies, one containing the view (xaml), and another containing the models and viewmodels. This works great on its own, but I'm having trouble figuring out how to make the view model consume the service. I tried making both the view assembly and the model/viewmodel assembly reference the service, but that didn't work. The code fails when I try to create a new instance of the client proxy class:
WCFServiceClient = new WCFServiceClient(new InstanceContext(this));
in the viewmodel. The exception thrown says:
Could not find default endpoint that references contract 'WCFService.IWCFService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
I know my WCF works because I have other client applications in winforms that are accessing it properly. Any idea on how this should be done?
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.
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
I am building a silverlight application using MVVM pattern but I don't understand what I am missing here...
ViewsProject (Silverlight Application) contains user controls and page. References ViewModelsProject.
ViewModelsProject (Silverlight class library) contains backend code of views. Also the business logic will reside in here. It will reference Models project.
ModelsProject (Windows class library) contains: Ado.net entity model of a local database and a WCF RIA DomainService built on the entity model. It's purpose is to get data from the local database and the entities are exposed via domain service.
Web project: Contains xap of ViewsProject.
Have I done everything correct so far? If yes then please help me understand:
How do I call the methods of the
domain service in the ViewsModel
project? If I reference the
ModelsProject, I get the error that
only silverlight projects can be
added.
If I change ModelsProject to a
silverlight class library project
then I can't add the entity model of
my database.
For client projects to use WCF RIA Service you need to set WCF RIA Services Link in project property.
As for modularity and separation in project architecture when using WCF RIA Services,
you can use WCF RIA Class libraries.
There isn't much sense in separating your views from your viewmodels IMHO. I've seen this approach used before but the view model (in my mind at least) represents a more 'view appropriate' abstraction of the data than the domain model can offer. The ViewModel provides a layer of indirection to allow the presentation to change without the model doing the same but it's little more than a sort of Adapter/Controller hybrid and lives alongside the view.
To answer your question though...
Typically, you'll have your SL project call your domain service (a web service usually) via commanding from your view to the viewmodel. The viewmodel command will then directly or indirectly make the web service call. This web service does not need to be a SL class library since it sits on the web server away from your client.
I get the feeling your thinking in terms of a desktop app here. Remember that the SL project runs client side and your data is not there. To wire all this up your gonna need some remote service to get the data from. A regular library reference is no good since the data is not on the client.
HTH, Stimul8d
I worked out the answer.
Change ViewModelsProject (Silverlight class library) to Silverlight Application type.
Check Enable Ria services during creation of the project.
In the view model class, add using ModelsProject.
Compile the ViewModelsProject.
All of the methods of the WCF Ria service will then appear in the code.