This has probably been discussed however all the threads I saw on this topic did not help me hence I’m posting.
I am attempting to host a WCF HTTP service on IIS 5.1. It is extremely basic. I created a virtual directory in IE called wcftest, which points to the actual folder containing the contents of the service. Here is the structure:
Web.config
ConsoleWCF.svc
[App_Code] \ Program.cs
Here is the code for ConsoleWCF.svc
<%@ ServiceHost Debug="true" Service="ConsoleWCF.WCFImplementer" Language="C#" %>
The Web.config looks like this:
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="ConsoleWCF.WCFImplementer"
behaviorConfiguration="ServiceBehavior">
<endpoint
address=""
binding="basicHttpBinding"
contract="ConsoleWCF.WCFInterface" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
And finally the Program.cs is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Description;
namespace ConsoleWCF
{
[ServiceContract]
public interface WCFInterface
{
[OperationContract]
[WebGet]
string GetData();
}
public class WCFImplementer : WCFInterface
{
public string GetData()
{
return "Tested Console WCF";
}
}
}
I can access this in IE by browsing to http://localhost/wcftest/ConsoleWCF.svc.
However I do not understand how to access the GetData method I have. When I did this using a stand-alone host, I had no issues accessing it. Any help is greatly appreciated.
In order for WCF to understand the
[WebGet]attribute, the endpoint needs to have a certain configuration, namely use thewebHttpBinding(notbasicHttpBindingas you do) and to have aWebHttpBehavioradded to it. If you change theweb.configto something like the one below, you should be able to browse tohttp://localhost/wcftest/ConsoleWCF.svc/GetData.