JasCav
JasCav

Reputation: 34632

Deploying WCF Service with ASP.NET Web Application

I am having some difficulty in deploying my WCF service alongside my ASP.NET web application. I have everything working on my local machine (defined my address, bindings, contract) and I can call the service from my ASP.NET (MVC) web application. (Base URL right now is http://localhost:####/Design_Time_Address/Fully/Qualified/Service/)

Unfortunately, once I attempt to deploy, things tend to blow up.

Here is what I currently am doing. Please let me know if one or more steps are incorrect.

  1. I have a service reference to my WCF Service in my ASP.NET MVC project.
  2. I first attempted to just deploy the MVC project using web deploy. The MVC part worked fine, but it couldn't find my service. (Although, interestingly enough, I can see the DLLs to my service on my host.)
  3. So, after messing with this for a bit, I then tried to upload my service separately via SFTP. I was able to hit the .svc file at one point, but lately I've been receiving errors. (I'm assuming this is because I've been trying to figure it out and have screwed it up royally.)
  4. I get a bit confused here because I don't understand what the address should be, or how I should configure it within the WCF App.config file so that my MVC application can access it.

Like I said, I was good until I had to deploy and, unfortunately, I am unable to find any tutorials that can help me out.

What am I not understanding is what setup I need to do to be able to access my service via my MVC application through the host server? Do I need to provide the service reference in my MVC project as I'm doing now? Do I have to configure something in the WCF service directly? Is it possible just to do web deploy and Stuff Just Works(TM)?

Appreciate your help.

Upvotes: 1

Views: 8433

Answers (2)

JasCav
JasCav

Reputation: 34632

So, it turns out the problem was very easily solved...unfortunately, in this case, I was a complete noob. Instead of creating a WCF Service Application, I had created a WCF Service Library. Switched to a WCF Service Application, set up my end points, added the DEPLOYED service to my MVC application, and it worked like a charm.

Feeling like a newbie today...

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

You could go by small steps.

  1. Create a new Visual Studio Solution.
  2. Add a new ASP.NET Empty Web Application project to it.
  3. Add a new WCF Service item to this application.
  4. Publish your application to the server.
  5. Ensure that the service has been successfully published to IIS by navigating to it (http://host/myservice/service1.svc).
  6. Add a new ASP.NET MVC 3 application to your solution. This will generate a strongly typed client proxy classes allowing you to consume the service and modify your web.config in order to add a <system.serviceModel> section containing a client endpoint whose address is pointing to the WCF service you have published
  7. Implement some code in your ASP.NET MVC 3 application that will call the service method
  8. Run the ASP.NET MVC 3 application locally and it should be able to call thepublished service.
  9. Publish your ASP.NET MVC 3 application

Now that you have setup everything you are ready to start implementing functionality into the service. You could either then test the service locally by changing the client endpoint in the web.config file of your ASP.NET MVC 3 application or leaving it and publishing the service.

Personally I don't use the Add Service Reference dialog in Visual Studio. I hate it when it touches to my web.config. I just hate when something touches to my code without my permission or verification. I use the command line svcutil.exe to generate a strongly typed client for my WCF services. So I type the svcutil.exe http://localhost:1234/service1.svc command which generates 2 files: a .cs file containing the client proxy and an app.config file containing the service endpoint configuration (which I usually throw away as I prefer to modify the web.config of my application manually). Then I copy the .cs file to my client application.

Upvotes: 1

Related Questions