none
How do I publish a WCF Service written in VB.NET in Visual Studio 2010 to IIS 7.5? RRS feed

  • Question

  • I have written a WCF service library using Visual Studio 2010 and I am wanting to publish it to IIS 7.5 (on Server 2008 R2).

    I'm looking for some pretty basic Step-by-step instructions on how to do this.  I understand there's some extra work involved, I can't just publish my Service Library to the web.

    Apparently I'm not a very good Bing-er.  I can't find anything appropriate to my situation.

    Can someone point me to some instructions that are relevant to Visual Studio 2010 and IIS 7.5?  I've seen some for VS 2008, but I'm looking for this specific circumstance.  I'm fairly certain it's easy, but I have no idea how to get from where I am (I've got a WCF Service Library that's functioning the way I want on my development machine) to where I want to be (I need to host this on IIS 7.5 so that others can consume it).

    Thanks as always for helping out a guy who knows just enough to be dangerous, but not enough to get his task accomplished without help from people who are smarter.

    Scott

    Friday, March 25, 2011 8:49 PM

Answers

  • HI Scott,

    Here's what I did to create the sample:

    1) Create a new WCF Service Library called MyServiceLibrary - I left the generated code as-is.
    2) Create a new WCF Service Application called MyService - I deleted the generated code: IService.cs, Service1.svc (Service1.svc.cs will be deleted when you delete Service1.svc)
    3) Add a project reference in MyService to MyServiceLibrary by right clicking the References folder under MyService in the Solution Explorer and selecting "Add Reference..", click the Projects tab in the Add Reference dialog and select MyServiceLibrary.
    4) Add a new .svc file to the MyService project by right clicking MyService in the Solution Explorer and select "Add" and "New Item". In the Add New Item dialog click "General" under Installed Templates and then Text File in the listbox. Name the file Service1.svc and click the Add button.
    5) Open Service1.svc in Visual Studio and add the following line of code:

     <%@ ServiceHost Language="C#" Debug="true" Service="MyServiceLibrary.Service1" CodeBehind="Service1.cs" %>

    6) Set MyService as the startup project and hit Ctrl+F5. This will build the solution and launch the WCF Service Host and the WCF Test Client. You can use the Test Client to make sure the service is responding correctly.
    7) Tell Visual Studio to host the service in IIS by:
     a) Right click MyService in the Solution Explorer and select Properties
     b) In the Properties page, click the "Web" tab, under the section labeled "Servers" select the "Use Local IIS Web Server" radio button. Leave the Project Url as the default (http://localhost/MyService), and click the "Create Virtual Directory" button.
    8) Rebuild the solution and the service will now be hosted in IIS.
    9) To verify the service is hosted correctly, open IE and type in the service's URL: http://localhost/MyService/Service1.svc
    Note: If you hit Ctrl+F5 it will still launch the service in  WCF Service Host

    You can download my sample projects here: http://cid-7c932c9763173a7c.office.live.com/self.aspx/Samples/MyServiceLibrary.zip

    Please let me know if you have any further questions.

     

    Michael Green
    WCF Documentation Team

    • Marked as answer by ASI Scott Tuesday, April 5, 2011 2:44 PM
    Thursday, March 31, 2011 10:14 PM
  • Scott,

    That's very strange. I did try with a VB project and I was able to add a new project to the solution.  It must be something in your environment, but I have no idea of what it could be. It might be a good idea to open a ticket for that part of the issue. On the IIS publishing side of the issue you can do it manually. What you need to do is the following:

    • Create a VB service library project called MyService
    • Create a .svc file for the service that looks like the following:
    <%@ ServiceHost Language="VB" Debug="true" Service="MyService.Service1" %>
    The Service attribute must be set to the fully-qualified name of the class that implements your service
    • Create a directory to hold your service files - call it c:\MyService for simplicity
    • Create a directory under MyService called bin
    • Place the service dlls in the bin directory
    • Place the .config and .svc in the \MyService directory
    • Open INetMgr
    • Right click "Default Web Site" and select "Add Application"
    • For Alias tye MyService
    • For Physical path type in c:\MyService
    • Click OK
    • That's it. You can now use IE to browse to your service, just type in http://localhost/MyService/Service1.svc, or you can call the service from a client.

    Let me know if you have further questions about the hosting in IIS issue.

    Thanks,

    Michael Green
    WCF Documentation Team

    • Marked as answer by ASI Scott Tuesday, April 5, 2011 2:46 PM
    Monday, April 4, 2011 5:36 PM

All replies

  • Scott,

    We have documentation on this, you can find it here: http://msdn.microsoft.com/en-us/library/aa751792.aspx and here: http://msdn.microsoft.com/en-us/library/aa751802.aspx. While these topics aren't necessarily written for IIS 7.5, the instructions should be accurate. Please give them a try and let me know if you run into any questions or problems.

    Thanks,

    Michael Green
    WCF Documentation Team

    Friday, March 25, 2011 9:53 PM
  • Ok, so I have my VS2010 WCF Service Library created.  I've tested it on my development machine and it functions as I expect it to.

    So, to publish it and host it on IIS, the documentation states that I need to "Create an .svc file for the WCF service."

    Does that go into my Service Library project?  Where?  I'm sorry for being such a noob, but I've read stuff on how to create the service library, but I have absolutely no idea, even after reading the two links that you provided, on how to actually, practically, utilize this service library that I'm using.  Where do I create the .svc file?  What do I do with it?  Do I "publish" the Service library from Visual Studio 2010 the same way I publish a web application?

    Again, my apologies for being such a noob.  You guys are probably rolling your eyes and thinking "this is really simple," and it probably will be once I've done it, but I'm scratching my head trying to figure out what to do next.

     

    Saturday, March 26, 2011 1:20 PM
  • Hey Scott,

    I think the easiest thing to do is create a WCF Service Application project in Visual Studio, reference your WCF Service Library in it, and edit the generated .svc file to specify the service type in your WCF Service Library. The reason I suggest this is, it's the easiest way to get a project to be hosted in IIS. Once you create the WCF Service Application project you can right click on the project name and choose properties. In the project properties dialog, click on the Web tab. In this page you can then tell Visual Studio to host the service on IIS by selecting the "Use local IIS server" radio button. Next click the "Create Virtual Directory" button to create the virtual directory. Next build the solution and all needed files (including the .svc file) will be copied to the appropriate virtual directory.  You can do all of this manually, create a virtual directory, copy the .dll from your WCF Service Library to the virtual directory, and copy the .svc file to the virtual directory.  I think using Visual Studio to set things up is easier.  Please let me know if you have any further questions. I think since you are not the first person to ask about this, we can create a new topic in the documentation that will walk you through this process. If you are interested I can send you a copy of it when it's written. (Probably not until next week).

    Thanks,

    Michael Green
    WCF Documentation Team

    Saturday, March 26, 2011 7:23 PM
  • Michael, this would be greatly appreciated.  Please send to sdart(at)asiflex(dot)com.  Or you can just point me to the link where you publish it.

    I have no doubt that it's a simple process.  I just need to be shown the first time. :)

    Sunday, March 27, 2011 1:11 PM
  • So, are you saying that I need to create a WCF Service Application project in addition to the Service Library Project I've already built?

    Let's talk about specifics.  I have a Service Library Project called "EmployerServiceWCF" and within that project are:  EmployerService.vb, IEmployerService.vb, Authentication.vb, and some other classes that I call.

    So now, I should build a WCF Service Application project?  I'll call it "EmployerServiceApp" to differentiate it from the library project that I've built.

    So now that I have this WCF Service Application in Visual Studio called "EmployerServiceApp."  How do I, as you say, "reference the WCF Service library in it?"  Don't I have to publish the Service Library on the server containing IIS first?  or does that happen automatically when I publish the EmployerServiceApp later?

    Sorry again, I'm sure I'm beating a dead horse, but I'm not yet seeing the big picture.  I'm confident the lightbulb will glow shortly, but it's not on yet.

    Wednesday, March 30, 2011 2:40 PM
  • Scott,

    I only suggested creating a new WCF Service Application project to make publishing the service to IIS a little easier. You do not have to do it that way. You can manually create a vdir and copy your service files (any dlls, web.config and the .svc file) to the appropriate directory. If you do create a new WCF Service Application, you can call it anything you want, it doesn't matter. When you go into the project properties to tell it to host the service on IIS, you can specify the URL for the service, it is independent of the project name (although it defaults to the project name).

    Once you have created the WCF Service Application project, set it to use the local IIS instance and built the project (this will publish the service to IIS). You can then go to your client project and right click on it in the Solution Explorer and select Add Service Reference.

    Let me know if you have further questions.

    Thanks,

    Michael Green
    WCF Documentation Team

    Wednesday, March 30, 2011 10:21 PM
  • That's a great suggestion.  Now I've created a new WCF Service Application and I've tested it on my local development machine using Visual Studio's built-in web hosting service.

    I presumed my next step was to publish it to IIS.  I did so using the only method with which I'm familiar: the File System method, where VS puts the whole site in a directory share on my network, which happens to be \\WEBSERVER\Inetpub\<AppDirectory>. 

    Next, I set up a "web site" in IIS and made the EmployerService.svc file the "default" file.

    Clearly that's not all that I have to do, because I'm still getting a 503 error when I try to connect to the service in another application. 

    What am I missing? What else do I need to do?

    Thursday, March 31, 2011 7:00 PM
  • HI Scott,

    Here's what I did to create the sample:

    1) Create a new WCF Service Library called MyServiceLibrary - I left the generated code as-is.
    2) Create a new WCF Service Application called MyService - I deleted the generated code: IService.cs, Service1.svc (Service1.svc.cs will be deleted when you delete Service1.svc)
    3) Add a project reference in MyService to MyServiceLibrary by right clicking the References folder under MyService in the Solution Explorer and selecting "Add Reference..", click the Projects tab in the Add Reference dialog and select MyServiceLibrary.
    4) Add a new .svc file to the MyService project by right clicking MyService in the Solution Explorer and select "Add" and "New Item". In the Add New Item dialog click "General" under Installed Templates and then Text File in the listbox. Name the file Service1.svc and click the Add button.
    5) Open Service1.svc in Visual Studio and add the following line of code:

     <%@ ServiceHost Language="C#" Debug="true" Service="MyServiceLibrary.Service1" CodeBehind="Service1.cs" %>

    6) Set MyService as the startup project and hit Ctrl+F5. This will build the solution and launch the WCF Service Host and the WCF Test Client. You can use the Test Client to make sure the service is responding correctly.
    7) Tell Visual Studio to host the service in IIS by:
     a) Right click MyService in the Solution Explorer and select Properties
     b) In the Properties page, click the "Web" tab, under the section labeled "Servers" select the "Use Local IIS Web Server" radio button. Leave the Project Url as the default (http://localhost/MyService), and click the "Create Virtual Directory" button.
    8) Rebuild the solution and the service will now be hosted in IIS.
    9) To verify the service is hosted correctly, open IE and type in the service's URL: http://localhost/MyService/Service1.svc
    Note: If you hit Ctrl+F5 it will still launch the service in  WCF Service Host

    You can download my sample projects here: http://cid-7c932c9763173a7c.office.live.com/self.aspx/Samples/MyServiceLibrary.zip

    Please let me know if you have any further questions.

     

    Michael Green
    WCF Documentation Team

    • Marked as answer by ASI Scott Tuesday, April 5, 2011 2:44 PM
    Thursday, March 31, 2011 10:14 PM
  • Again, please pardon my stupidity.  I'm attempting to follow these instructions verbatim, and I'm getting tripped up in Step #3.  I'm doing this with VB instead of C#, does that matter?  But in Step 3, you state that I should "click the Projects tab in the Add Reference dialog and select MyServiceLibrary" (or the name of the service library which I created.)  However, nothing appears in the Projects tab.  I don't know how to add multiple projects to a single solution in Visual Studio 2010.  It doesn't seem to work the way it did in VS 2008.  So, my Service Library is in a different solution.  Is there a way to add multiple VB projects to a single VS Solution in VS 2010?  If I use the "browse" tab, I can find the other solution, but then what file do I add to the References?  The one in the \obj folder?  The one in the \bin folder?

    Once I figure out what I'm  supposed to be doing in Step 3, I'll continue on with the steps as outlined above.  Thanks.

    Scott

     

    Friday, April 1, 2011 6:57 PM
  • Hi Scott,

    Sorry that that solution was in C# instead of VB, that shouldn't matter though. I think the problem is that when you created the new project it wasn't added to the existing solution. To do that open up your WCF Library project, right click on the Solution (it will be labled "Solution MyServiceLibrary") in the solution explorer and select Add.. and then "New Project". In the Add New Project dialog select WCF Service Application. This will add the new project to the existing solution.

    Give this a try and let me know how it goes.

    Thanks,

    Michael Green
    WCF Documentation Team

     

    Friday, April 1, 2011 7:12 PM
  • Hi Michael, and thanks for your patience with me.

    I agree that what you are stating in your last message is what happens under VS 2008, but under VS 2010, I cannot get that to occur.  In Solution Explorer, the top level item is the PROJECT, not the SOLUTION.  This seems to be the case even when I try to open the .SLN file.  So when I right-click on the Project (which is the top-level...there's no solution above it, even when I click "Show all files"), the only options I get are the ones related to the individual project.  I don't seem to be able to see or manipulate anything at the solution level like I could in VS 2008.  I think this is why these instructions have been so confusing for me.  I wish I could copy and paste  a screenshot of what my Solution Explorer looks like right now, but there doesn't seem to be a mechanism for uploading images in these forums.

    My Service Library is called "EmployerServiceWCF" and when I have "show all files" toggled, this is what it looks like:

     

    EmployerServiceWCF
    > My Project
    > References
    > bin
    > obj
       App.Config
       EmployerService.vb
       EmployerServiceWCF.vbproj.vspscc
       IEmployerService.vb

     

    So I'm right-clicking on EmployerServiceWCF at the top, but I suspect that's the PROJECT level, not the SOLUTION level.  Is this a VB thing?  Under VS 2008 I can see the Solution Level and add projects to it, but in VS 2010, it seems that I can only see the PROJECT level, and therefore am limited to a one-project solution.

    I'm sure there's something simple that I can toggle so that I can follow your instructions, but I can't for the life of me figure out what I need to do.

    Thanks again for whatever help you can offer.

    Friday, April 1, 2011 8:22 PM
  • Hi Scott,

    Wow that is really strange. I'm using VS 2010 and it works as expected for me. What flavor of VS 2010 are you using? Are you using Visual Studio Express? I'm going to install that and see if I get the same behavior.

    Thanks,

    Michael Green
    WCF Documentation Team

     

    Friday, April 1, 2011 8:47 PM
  • No, I'm running VS 2010 Premium with MSDN.

    Can you try and see if the behavior is the same when doing a VB service?  Perhaps that's an idiosyncracy of C# only?  But if that's the case, then I'm still looking for a way to publish my VB Web Service Library to IIS.

    Is it time for me to open a support ticket, then?

    Friday, April 1, 2011 11:28 PM
  • Scott,

    That's very strange. I did try with a VB project and I was able to add a new project to the solution.  It must be something in your environment, but I have no idea of what it could be. It might be a good idea to open a ticket for that part of the issue. On the IIS publishing side of the issue you can do it manually. What you need to do is the following:

    • Create a VB service library project called MyService
    • Create a .svc file for the service that looks like the following:
    <%@ ServiceHost Language="VB" Debug="true" Service="MyService.Service1" %>
    The Service attribute must be set to the fully-qualified name of the class that implements your service
    • Create a directory to hold your service files - call it c:\MyService for simplicity
    • Create a directory under MyService called bin
    • Place the service dlls in the bin directory
    • Place the .config and .svc in the \MyService directory
    • Open INetMgr
    • Right click "Default Web Site" and select "Add Application"
    • For Alias tye MyService
    • For Physical path type in c:\MyService
    • Click OK
    • That's it. You can now use IE to browse to your service, just type in http://localhost/MyService/Service1.svc, or you can call the service from a client.

    Let me know if you have further questions about the hosting in IIS issue.

    Thanks,

    Michael Green
    WCF Documentation Team

    • Marked as answer by ASI Scott Tuesday, April 5, 2011 2:46 PM
    Monday, April 4, 2011 5:36 PM
  • I did find a way to add a new project to a solution, but I still can't do it by right-clicking...

    To add a second project to an existing solution, I selected File, Add, New Project from the menu.  Not sure why I can't get "Add New Project" in the contextual menu, but as long as I can accomplish it another way, I'm happy.  I'm going to try following your instructions now and see if I can't make 'em work.

    Thanks,

    Scott

    Tuesday, April 5, 2011 1:35 PM
  • I have successfully created a multi-project solution, and incorporated the WCF Service Library into the WCF Application.

    Hooray! I'm now where I wanted to be a week and a half ago.  But I still wouldn't be there now if it hadn't been for your patience, Michael.  Thanks very much for teaching a noob how to publish a WCF Service!

    Scott

    Tuesday, April 5, 2011 2:46 PM
  • My pleasure Scott.

    Take care,

    Michael Green
    WCF Documentation Team

    Tuesday, April 5, 2011 6:08 PM
  • Sorry to open this question again - but Michael, I tried following your solution to publishing a simple WCF Service on IIS and I am able to get it up until step 8.

    When I try to "9) To verify the service is hosted correctly, open IE and type in the service's URL: http://localhost/MyService/Service1.svc"

    I get the following error:

     

    Service 'MyServiceLibrary.Service1' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.

    Please help me figure this out, I've spent hours trying to get a WCF project up and running on IIS but don't know how to continue.

    Many thanks!

    Thursday, August 18, 2011 9:14 AM