Should I use WCF instead of DLL in c# - wcf

I need some advice about using WCF or DLL in my program. I am developing a program that will be Desktop App and Web App. The architecture is multi tiers. What should I do in Bussiness layer, should I just make it as a namespace and build it to be a dll then in my Desktop App and Web App I add reference this dll OR should I make the business layer be a web service, then I can use in my apps. What I have to consider when using a web service instead of dll.

Just to get started you could create one Solution that includes:
Business logic project
Web App project
Desktop project
Web App project and Desktop project will just reference your Business logic project. Then(if needed) you could continue to separate Business logic project to e.g. Data Access project, Service Layer project etc.
Then if you will feel that you need "real" WCF service it would be easy to create one from your decoupled architecture.

You should use restful service like http webapi which has broad reach of clients

Related

Best practice for where to place Services folder in C# Blazor Web Assembly (ASP.NET Core hosted) application?

Where is the best place to create a Services folder in a C# Blazor Web Assembly (ASP.NET Core hosted) application? A Web Assembly (ASP.NET Core hosted) application has 3 projects for 1. Client, 2. Server and 3. Shared.
My initial thought is to place the Services folder in the root of the Shared project. Is there a best practice of where the Services folder should be placed for this kind of application, maybe in the Server project for example?
I have created a Service to read a CSV file which I have registered with the Dependency Injection service to make it easier to access throughout the project and also for testing. I will be adding other services as well so would be good to know if anyone else has a preferred place to add those services normally?
Thanks for your time.
It's important to understand what is sent to the browser and what is kept on the server-side. The Client project has reference to the Shared project (by default), so once compiled both projects Client and Shared will be sent to the browser (as .dll). The Shared project is also referenced by the Server project, and it acts like a "bridge", holds some common constructs. Having that said, I'd suggest you do the following:
Client project - You place all your client-side logic, your razor components, your views, and the code that calls various API endpoints (or it might be gRPC calls).
Server project - Here you keep all your API endpoints and back-end services.
Shared project - Since this is referenced by both, a copy is sent to browser, and another one kept as part of your server application. This is a good place to put all your Dto models. Avoid placing any services or any logic-related constructs. The common constructs between Client and Server are the models only. Having a shared project is just a convenience, you can of course opt it out completely, and duplicate your models in both places.

WCF with MVC application and mobile app

I'm just wondering how to approach to my project.
In my application I have:
MVC4 project
DB_Project with Interfaces and Models
Repository_Project with interfaces implemantation - I'm using Ninject
Next step is mobile app(XAMARIN), and here is the question:
What kind of WCF project should I choose and why...WCF Service Application or WCF Service Library?
Should I add this project like any other or create separate one?
After choosing WCF project, how to use reference to Repository_Project - is this the right way?
I will give you some thoughts to consider.
1- Your Xamarin app must communicate with an asp.net web api / mvc exposed to the internet. I dont recommend exposing a WCF service to the internet for many reasons.
2- In the Data layer, repositories are abstractions to access your EF dbContext and not to call WCF services.
3- You only add complexity when justified. If you are willing to create WCF project for the xamarin app to communicate with, then i hardly discourage you. WCF project may be created in your case if you have some security policy that enforces 3-tiers architecture where the web api needs a middle tier to access the database. Otherwise, you dont need it.
2-tiers:
Xamarin -> web api -> SQL Server
3-tiers:
Xamarin -> web api -> wcf -> SQL Server

Web Hosted WCF REST Service with plugable endpoints (is this possible)?

I'm a bit new to WCF, so please bear with me. I have a very simple REST Service written up using .NET 3.5, which is exposed through a asp.net web application through a SVC file. Everything is working as expected.
What I would like to know is if it is possible for me to create a plugin structure in WCF, so that I can have third party developers write up expose their functionality through my service. I'm hoping it's possible to dynamically create my endpoints through code, at the moment everything is in my web.config and service.svc files (as far as exposing the contract).
In the end, what I would like to have an active running service that auto checks for new assemblies (if added to the plugins directory), and would automatically add new endpoints, which could have completely different functionalities. One could be a file transfer plugin, another could be a calculator, etc.
But first I need to know if it's even feasible... currently I'm looking into MEF to see if that might help out, as I'm used to just loading DLLs manually (in Desktop apps).
It is possible to use MEF through WCF, I have worked on a similar project in the past. You could expose functions from the plugin DLL's through MEF assume the implementer of the MEF interface is implimenting a function that starts a new WCF service with it's own end points, then call that function from the main service.
See some sample projects below, although none of them are doing what you are asking it is possible that the MEF plugins could have a service host that's starting their very own service with their own end points.
Creating WCF Service Extensibility through MEF
A sample demonstrating how WCF and MEF play together

Integrating WF4.0 with Silverlight 4.0

I am new to both Silverlight and WF (both 4.0 version), i was wondering if we can integrate WF4.0 with Silverlight 4.0 in such a way that, when we click on some button in sliverlight UI the workflow should be executed and the output from the final activity of the workflow is displayed in the Silverlight screen. If it can be done then please provide me with some link or any tutorial where i can learn about this and start implementing.
Thanks in advance.
In WF 4.0 you can have workflows started (or progressed) by WCF endpoints. Therefore, if you can call the WCF endpoint from your Silverlight application you should be able to do this quite easily. Lots of information on Microsoft's WF Developer Centre.
Assuming you are using Visual Studio 2010, you can get up and running with a very simple Silverlight -> WF example very quickly...
Create a new project (and new solution) from the 'WCF Workflow Service Application' template. The project will be named DeclarativeServiceLibraryX. This should give you a very simple WorkflowService definition using SequentialService that simply receives the request from a client (with a single integer argument) and sends a response (with the same value). This project is created as a web project so includes a Web.config.
Create a new Silverlight 4 application. You will be asked if you want to host the Silverlight app in the existing web project (created in step #1). Probably a good idea to say yes.
In the Silverlight application, select 'Add Service Reference...', then 'Discover/ Services in Solution'. Service1.xamlx will appear as an option, select it and click Ok.
VS will then generate a WCF service reference client. You could then add a TextBox & Button to capture some data, create the client and send the service call across the wire to the WCF Workflow Service. This Workflow Service could then be modified as necessary (or use these steps to add a WCF Workflow Service to your own web project).
One area that might be challenging is modifying the WCF service bindings to be compatible with Silverlight; perhaps create a Silverlight-compatible WCF service in your server-side project first, then create a WF WCF endpoint and look at the generated code & config to see how to put things together.
The MSDN Endpoint blog is also a useful resource for learning more about WF and WCF (especially with the new style lightweight REST-style 'WCF Web HTTP' bindings, which might be more suitable for consumption by a Silverlight client.
I am assuming that you don't want to host the workflow inside the Silverlight app itself, as WF is a full .Net framework component rather than being Silverlight compatible. I'm sure you could write your own lightweight workflow framework that runs inside Silverlight, but given workflow is generally a multi-user, server-side concern this probably wouldn't be very useful concern.
I found an example with WPF here for these samples. Hope they will help you a bit or at least give a general look at this topic.
Workflow Foundation is not included in the Silverlight 4.0 runtime and thus cannot be used within a Silverlight app. So Silx answer do not relate at all to Silverlight. And James Websters answer is the only solution to make use of WF from Silverlight.
You cant use WF with silverlight.... the only way is , You can call WCF service to access WF as explained by James Webster.

Use a separate WCF project with Silverlight

I am working on a Silverlight application that uses WCF. I need to have my WCF project separate from the ASP.Net application that will host my Silverlight project. I am looking for some guidance on how I should organize my solution and list gotchas other people have experienced during debugging and deployment.
Specifically my questions are
What type of project should I use for the WCF service?(A WCF project, an ASP.NET project with self-hosted WCF services, something else)
What do I need to so to get it so that when I press F5 I can debug both my Silverlight project and my WCF service? Will I need a cross-domain policy just to debug the thing?
Some background info on why I want to do this:
I have legacy web application that I am gradually converting over to a Silverlight application. Because it is a large web application some of its features will be converted to Silverlight before others.
The legacy web application has lots of code in it that is no longer used. Much of the code that is no longer used references 3rd part assemblies. This is why I want to get rid of the old web application. So obviously I don't want to host WCF services that will be kept for future versions in it. That is my reason for wanting to make the WCF project separate.
We're doing the exact same thing.
We're using a WCF project just in case we have to change how it's hosted in the future. (I.E. no longer using IIS)
2.a. You can have a solution with your silverlight projects, and your wcf project. The silverlight project will have a service reference to the wcf service in your solution. That allows you to debug using F5. However, when you go to deploy, you will have to change your app.config service URIs to refer to your production location.
2.b. You will only need a cross-domain policy file if your fully qualified domain names are different for the wcf service and the silverlight app. Ours happen to be different. Here is an excellent article on when to use the policy file: Clicky
Good luck!
Just remember that when you get ready to deploy, if your service is going to be hosted on a different machine than your app, you need to deploy the service first. Then re-configure your service reference, and finally re-compile your Silverlight before deploying. Otherwise, your Silverlight app will look for the service on your local machine instead of where you deploy it.