如何为 WCF 自托管服务定义配置多个端点?

发布于 2024-12-21 05:09:26 字数 1175 浏览 2 评论 0原文

我有两个 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();

I have two WCF Web API Contracts. Before this, I was happy that I could use TestClient. But after I implemented the second one I had to define endpoints (and could not use the default one) and after that, either I see nothing in browser or this message saying that "This XML file does not appear to have any style information associated with it." when I try to go to the endpoint address. It is the same when I try the config file (although I do not know how to set "EnableTestClient = true"). I really appreciate any help.

        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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吲‖鸣 2024-12-28 05:09:26

我不认为应该使用多个端点来公开不同的 API。它们用于公开具有不同绑定的相同合约。
您应该为每个 API 创建一个新主机。不过,您可以在它们之间共享配置。

I don't believe that multiple endpoints should be used to expose different APIs. They are for exposing the same contract with a different binding.
You should create a new host for each API. You can share the config between them though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文