Can I add a WCF service to an existing project - wcf

Looking at an earlier 3.5 based solution, there is an WCF service within the same web project. I thought WCF services generally got their own project.

I usually separate my WCF projects out for maintenance purposes, but they can be within a web project. It is basically the same thing as the old ASMX [WebMethod] process. In fact, any method in a code-behind of a web form can be turned into a web service method by decorating the method accordingly.

Related

Hosting WCF service and WebAPI in the same WebApplication

I've implemented an OData service using ASP.NET WebAPI. I also have some existing web methods in a seperate WCF project which is hosted in an ASP.NET Web Application.
By copying some bits of web config around and copying a couple of code files I've managed to get the WCF methods hosted in the WebAPI project.
Everything seems to be working but I've got a nagging doubt I'm doing something horribly wrong that's going to break when I least expect it.
Is this a good idea?
Depends on your anticipated call volume. The only problem I can think of with this is that incoming WCF requests will be serviced from the same dispatcher thread pool as the OData service. This makes it more likely that you will suffer availability based issues on either endpoint.

Not able to add a Web reference to a WCF Service library using basicHttpBinding

I have two instances of VS2010 running on same machine.One VS instance has a WCF service with basicHttpBinding.
Now as i have read in books, for calling this WCF service with basicHttpBinding, i have to Add a Web reference to it rather than Service Reference.
I ran the project containing the WCF service and from other VS instance try to add a Web reference, this is the URL which i gacve(I got it from WCFClientHost )
http://localhost:8732/Design_Time_Addresses/WcfServiceLibraryBasicHttpBinding/Service1/mex
But i get Http 400 error everytime i try to add the WCF service.
Please let know what i am doing wrong.
You should keep two things apart:
Add Service Reference adds a service interface based on the .NET 3.0 and up WCF runtime. It supports all WCF bindings - including basicHttpBinding
Add Web Reference is the old-style, .NET 1.x/2.x method of adding a reference to an ASMX web service ("ASP.NET web service"). This technology is outdated, and has been fully replaced by WCF as of .NET 3.0. ASMX only ever supported what is more or less equivalent to basicHttpBinding.
The ASMX technology is outdated, and you should only ever use this if you really can't make WCF work (but in my 3 years of writing and consuming a plethora of web services, I have never seen such a case) - avoid this unless you absolutely can't make WCF work - for whatever weird reason that might be...
The link you gave to the CodeProject article has a entirely plain wrong statement that you need to use Add Web Reference for basicHttpBinding - that is just plain NOT TRUE.

Is it really worth using the WCF REST Service Application type in Visual Studio 2010?

In the past, I have created a "robust" WCF service that can accept a complex (consumption of the service in a project) or RESTful requests.
I'm creating a new service and wanted to ease the creation of the restful endpoints. So I see the WCF Rest Service Application, which I'm trying out.
The problem now, is that if I wanted to use this service from another .Net application, I would now have to go through the process of writing the completed event parsing/de-serialization.
I think in trying to over-simply the initial process, I will complicate the consumption process.
Are there any simpler ways around this, and is it best to stick to the main WCF service type and simply decorate the service contract methods appropriately.

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.