WCF Rest Service Template 40 on IIS 7.5
I am attempting to get the WCF Rest Service Template 40 (CS) which is an online template in VS 2010 to deploy to IIS 7.5 on Win Server 2008 R2. We havn't changed the template at all and are trying to get this call to work:
public class Service1
{
// TODO: Implement the collection resource that will contain the SampleItem instances
[WebGet(UriTemplate = "")]
public List<SampleItem> GetCollection()
{
// TODO: Replace the current implementation to return a collection of SampleItem instances
return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
} ....
We've tried:
- manually creating an .svc file as this template doesn't have one. looks like:
<%@ServiceHost language=c# Debug="true" Service="WcfRestService2.Service1"%>
- publishing as a website and adding it as a website in IIS.
- we've installed .net framework 4.0 on IIS and that is working.
- adding some webconfig stuff to attempt to get the endpoints from the Global.asax.
- a bunch of other stuff...
I am pulling my hair out over this and sorry I c开发者_JAVA技巧an't be more specific about what exactly is going on. The problem we are getting is the service calls such as http://localhost/Service1 can't be found thru IIS but they work fine in VS.
Here is the webservice file:
how do you insert xml? http://www.nitricburnstudios.com/Web.config
After much frustration finally figured out how to get this working.
You have to enable HTTP redirection in IIS.
This can be done by going
- Control Panel -> Programs and Features
- Turn Windos Features on or off
- Under roles, add the web server -> common http features -> http redirection role
This was kind of listed here: http://blogs.msdn.com/b/rjacobs/archive/2010/06/30/system-web-routing-routetable-not-working-with-iis.aspx
By default when you switch to publishing to IIS, it does so to a vdir instead of the web site root, so I'm guessing you need to check the vdir it's installing to (project properties, web) and change the url you're trying to access to http://localhost/WcfRestService1/Service1 (or whatever).
When I create a project from the template, switch to IIS publishing, hit F5, and then hit that url, I get the expected output just fine:
<ArrayOfSampleItem xmlns="http://schemas.datacontract.org/2004/07/WcfRestService1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<SampleItem>
<Id>1</Id>
<StringValue>Hello</StringValue>
</SampleItem>
</ArrayOfSampleItem>
精彩评论