Add WCF service as link from website project to webapplication project - wcf

In my solution I have a "website" project and "WebApplication" project. In the website project I have a WCF service under folder called Services. So by default it places MyService.cs file under App_Code folder.
Now I am trying to add this same WCF service as link file into my WebApplication project. But as the [.svc & .cs] are in two different location in website project it is not being picked up as a service in WebApplication project.
Any solution to this problem ? Any thoughts or ideas ?
Thanks in advance,
Keyrav

I think your best bet would be to totally separate out the WCF service into its own class-library assembly (no code in the *.svc.cs code-behind or the App_code directory), and then reference that WCF service assembly from your different projects and web sites.

Related

Must I add a WCF service class library in order to host a WCF Service in a Windows service?

I read about how to host Wcf Service in a Windows service. There is a guide here:
http://msdn.microsoft.com/en-us/library/ms733069.aspx
But what I did was just to create new WCF Service class and interface inside the same project of the Windows Service instead of creating a new project separatly for the Wcf service.
Is it possible to do it? because I can't add a service reference to that service from other projects in the solution. It can't find it.
OK, here is what I found.
Creating a new solution with one Windows service project with a Wcf service class and one Asp.Net folder.
Running the Windows service.
Trying to add a Service reference to the Asp.Net project.
Result: Service can't be found.
Adding a new project which contains a Wcf project to the solution.
Adding a reference to it from the Windows Service.
Trying to add a Service reference to the Asp.Net project.
Result: Service found.
Reading this link:
http://msdn.microsoft.com/en-us/library/ms731758.aspx it's done similar to what I did in the test solution, but still there is a need to write some code in the Windows Service.
In this link:
http://msdn.microsoft.com/en-us/library/ms731758.aspx
They show how to host it without creating a separate project.
So the answer to the question is no, you must not, but you have to write some code for hosting the service and can't just use the configuration file.
Note the windows service must be running so you can successfully add the reference.

How to generate a wsdl file of a wcf service library project?

I have a few Wcf service library projects (not Wcf service application) in my solution. I have to give the .wsdl files of the projects to my collegue who will consume the services.
How can I do that?
Thanks in advance,
You can use the WCF Service Host to start a new instance of your service, and then add ?wsdl to the service address to access the wsdl (http://localhost:1234/MyService.svc?wsdl for instance).
WcfSvcHost's syntax is the following:
WcfSvcHost.exe /service:<PathToServiceDLL> /config:<PathToServiceConfig>
Follow these steps:
Go to IIS add new application under the default web site.(alias:test
physicalPath: c:\test), dont press test connection
On your wcf project right click and run publish choose your new
application on IIS.
Goto IIS to test application, right click on the svc file and browse - its open IE.
On the url address on the IE add to the address ?wsdl. and ENTER it.
good luck

WCF, Silverlight: clientaccesspolicy.xml not being found

I"m trying to connect my Silverlight application to a WCF service that I'm hosting myself. I've created a clientaccesspolicy.xml file, and placed it in the service host project's root, but when I try to hit the service, my http sniffer says it can't be found. Specifically the file it's looking for is http://localhost:8080/clientaccesspolicy.xml.
I'm running the server and the silverlight app in debug mode in Visual Studio 2010. Do I need to put the file somewhere else?
The clientaccesspolicy.xml file must be in the root of the domain where the service is hosted. You may already have it there but the virtual path of the web site or web application from the property page will need to be changed to "/"
See this page
for more information.
I did not understand how you're hosting your WCF service?
Is it hosted in a asp.net application or a windows host (self-hosting)? If the latter is the case, you may have to implement a clientaccesspolicy service that provides the content of the clientaccesspolicy.xml file on request.
For example like this.

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.

Adding .svc file missing

I need to add a .svc file to WCF Service Library I have added to a solution (This doesn't have the .svc file). If I specify this file through ad new item (eg test.svc), this is an installer file not the WCF file.
How can I add this file to my project?
Thanks
You cannot add a .svc file to a WCF service library - you need to add the WCF service file to a ASP.NET web site or ASP.NET web application in your solution.
In a web application or web site, you can right click on the project, choose "Add New Item", and then pick "WCF Service" from the dialog. This will add the necessary .svc file to your web site or web app.
The svc file must to be in a web app/web site as a container - it cannot reside in a WCF service library.
Marc
Just right click on sub folders and select "convert to Application"