UPDATE The below problems might be due to net.tcp not useable on IIS express. Good answers (preferably examples) are still very welcome.
I'm trying to host a WCF service in a IIS without using the web.config file (msdn documentation on the basics on that). I want to use sessions and the NetTcpBinding, but I seem to run into problems getting the metadata to work. I've tried quite a few things. Here is my current code:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class InternalInternalESensService : IInternalESensService
{
public static void Configure(System.ServiceModel.ServiceConfiguration config)
{
NetTcpBinding wsBind = new NetTcpBinding(SecurityMode.Transport);
config.AddServiceEndpoint(typeof(IInternalESensService), wsBind, "net.tcp://localhost:42893/ESens/ESensInternalService.svc");
// config.AddServiceEndpoint(typeof(IInternalESensService), basic, "basic");
// config.Description.Endpoints.Add(new ServiceMetadataEndpoint(MetadataExchangeBindings.CreateMexHttpBinding(), new EndpointAddress(config.BaseAddresses[0])));
config.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true, HttpGetBinding = MetadataExchangeBindings.CreateMexHttpBinding()});
//config.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
config.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });
}
public string Test(string input)
{
return "Hello " + input;
}
The uncommented code shows some of my desperate tries that didn't work. It implements the interface:
[ServiceContract(Name = "ESensInternalService", Namespace = Constants.WebserviceNameSpace + "/ESensService", SessionMode = SessionMode.Required)]
public interface IInternalESensService
{
[OperationContract]
string Test(string input);
There are some more methods in the interface and class implementation, but they are not relevant for the question/problem.
To host it in IIS I use a svc file. The content looks something like this:
<%@ ServiceHost Language="C#" Debug="true" Service="Esens.Integration.WebService.InternalInternalESensService" %>
I've gotten a lot of different exceptions depending on what I did.