3
Reply

Problem Hosting WCF application on IIS 5.1

Nathan Lim

Nathan Lim

Feb 23 2011 2:12 PM
4.3k

Hello my friends,

I am new to WCF and created a very simple application that runs perfectly under the Visual Studio 2008 environment but has problems running under an IIS 5.1 host.

Here are the details of my application. It is very simple :

1) I created a WCF application that simply allows users to enter their name and a comment.
The name of the application is : EvalServiceLibrary
Contents of the C# code are as follows :

using System.Text;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.ServiceModel;
namespace EvalServiceLibrary
{
[DataContract]
public class Eval
{
[DataMember]
public string Id;
[DataMember]
public string Submitter;
[DataMember]
public string Comments;
[DataMember]
public DateTime TimeSubmitted;
}
}
namespace EvalServiceLibrary
{
[ServiceContract]
public interface IEvalService
{
[OperationContract]
void SubmitEval(Eval eVal);
[OperationContract]
List<Eval> GetEvals();
[OperationContract]
void RemoveEval(string id);
}
}
namespace EvalServiceLibrary
{
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class EvalService : IEvalService
{
List<Eval> evals = new List<Eval>();
#region IEvalService Members
public void SubmitEval(Eval eval)
{
eval.Id = Guid.NewGuid().ToString();
evals.Add(eval);
}
public List<Eval> GetEvals()
{
return evals;
}
public void RemoveEval(string id)
{
evals.Remove(evals.Find(e => e.Id.Equals(id)));
}
#endregion
}
}

2) I then created two Endpoints. One with wsHttpBinding, the other a metadata endpoint with mexHttpBinding.

APP.CONFIG file contents are as follows :

---------------------------------------------------------------------------------
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="EvalServiceLibrary.Service1Behavior"
name="EvalServiceLibrary.EvalService">
<endpoint address="ws" binding="wsHttpBinding" contract="EvalServiceLibrary.IEvalService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/EvalService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="EvalServiceLibrary.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

When I build the above application, it creates the following dll :

EvalServiceLibrary.dll

and

EvalServiceLibrary.pdb

3) I then added a web site to my solution that refers to the above library I created.

I called my .svc file : Eval.svc

Here is its content:

<%@ ServiceHost Language="C#" Debug="true" Service="EvalServiceLibrary.EvalService" %>


I also have a Web.config file with the following contents :

<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="EvalServiceLibrary.EvalService">
<endpoint address="" binding="wsHttpBinding" contract="EvalServiceLibrary.IEvalService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="basic" binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation defaultLanguage="c#" />
</system.web>
</configuration>

4) I run it under DEBUG ( press F5 ) in Visual Studio 2008 and it works great. I see the WCF Test Client window come up and I see the 3 methods I created exposed : SubmitEval(), GetEvals() and RemoveEval().

5) I then tried hosting the above application under IIS 5.1

Here is how I configured it under IIS 5.1:

I created the Application Name : EvalServiceSite

The Directory it points to (the Local Path ) is : C:\Demos\EvalServiceSite

I selected all the following to be true : READ, LOG VISITS and DIRECTORY BROWSING

ASP.NET version : 2.050727

Virtual Path : /EvalServiceSite

File Location : C:\Demos\EvalServiceSite\web.config

Directory Security has the following selection checked:

Anonymous access, Allow IIS to control password, Integrated Windows Authentication

When I tried hosting it on IIS 5.1, I am getting the following error when I tried entering the following URL on the browser :

http://localhost/EvalServiceSite/Eval.svc

_________________________________________________________________________________

Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable. Please hit the "Refresh" button in your web browser to retry your request.

_________________________________________________________________________

However, when I used the following URL :
http://localhost:1031/EvalServiceSite/Eval.svc
It works. I get the following page coming up:
____________________________________________________________________________________

EvalService Service

You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:


svcutil.exe http://localhost:1031/EvalServiceSite/Eval.svc?wsdl
This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:

C#
class Test
{
static void Main()
{
EvalServiceClient client = new EvalServiceClient();
// Use the 'client' variable to call operations on the service.
// Always close the client.
client.Close();
}
}

____________________________________________________________

So, my question to you folks who I hope can help me is this :

1) Why am I getting the Server Application Unavailable message when I host it under IIS 5.1 ( I think the TCP port it is using is 80 )? How can I get around this problem ?

2) Why am I successful when I use localhost:1031 ?

3) Also, I do not recall specifying the port number 1031 anywhere in my solution, how did this port get assigned ?

I have been tearing my hair out for hours trying to solve this problem for hours. I would appreciate your kind help.



Answers (3)