【发布时间】:2016-10-11 01:46:58
【问题描述】:
更新 以下问题可能是由于 net.tcp 在 IIS express 上不可用。好的答案(最好是例子)仍然很受欢迎。
我试图在不使用 web.config 文件 (msdn documentation on the basics on that) 的情况下在 IIS 中托管 WCF 服务。我想使用会话和 NetTcpBinding,但我似乎遇到了让元数据工作的问题。我已经尝试了很多东西。这是我当前的代码:
[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;
}
未注释的代码显示了我的一些绝望尝试,但没有成功。它实现了接口:
[ServiceContract(Name = "ESensInternalService", Namespace = Constants.WebserviceNameSpace + "/ESensService", SessionMode = SessionMode.Required)]
public interface IInternalESensService
{
[OperationContract]
string Test(string input);
接口和类实现中还有一些方法,但它们与问题/问题无关。
为了在 IIS 中托管它,我使用了一个 svc 文件。内容如下所示:
<%@ ServiceHost Language="C#" Debug="true" Service="Esens.Integration.WebService.InternalInternalESensService" %>
根据我所做的不同,我遇到了很多不同的例外情况。
【问题讨论】:
标签: c# wcf configuration nettcpbinding