我有两个 WCF Web API 合约。在此之前,我很高兴能够使用 TestClient。但在我实现第二个端点之后,我必须定义端点(并且无法使用默认端点),之后,我在浏览器中看不到任何内容,或者这条消息说“此 XML 文件似乎没有与以下内容关联的任何样式信息”:它。”当我尝试访问端点地址时。当我尝试配置文件时也是一样的(尽管我不知道如何设置“EnableTestClient = true”)。我真的很感谢任何帮助。
var baseurl = new Uri("http://localhost:7000/api/v1.0");
var config = new HttpConfiguration() { EnableTestClient = true };
config.CreateInstance = (type, context, request) => container.Resolve(type);
var host = new HttpServiceHost(typeof(ServiceAPI), config, baseurl);
host.Description.Behaviors.Add(
new ServiceMetadataBehavior() { HttpGetEnabled = true, HttpGetUrl = baseurl });
// Add MEX endpoint
//host.AddServiceEndpoint(
// ServiceMetadataBehavior.MexContractName,
// MetadataExchangeBindings.CreateMexHttpBinding(),
// "mex"
//);
//host.AddServiceEndpoint(typeof(IStatAPI), new WebHttpBinding(), "/stat");
//host.AddServiceEndpoint(typeof(IAlarmAPI), new WebHttpBinding(), "/alarm");
host.Faulted += (s, e) => Debug.WriteLine(e);
host.Open();
最佳答案
我不认为应该使用多个端点来公开不同的 API。它们用于公开具有不同绑定(bind)的相同契约(Contract)。 您应该为每个 API 创建一个新主机。不过,您可以在它们之间共享配置。
关于wcf - 如何为 WCF 自托管服务定义配置多个端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8497379/