1

我已经使用 WCF Web API 实现了一个安静的服务,我想在 IIS 中发布它。在开发过程中,我将该服务用作控制台应用程序,所有配置都是通过 API 进行的。现在我正在尝试将服务发布为 ASP.NET 应用程序,而我看到的唯一方法是以某种方式将所有配置移动到 Web 配置文件中。

这里的编码配置:

var cfg = HttpHostConfiguration.Create()
                .AddMessageHandlers(typeof(AllowCrossDomainRequestHandler));

using (var host = new HttpConfigurableServiceHost(typeof(RESTfulService), cfg , new Uri("http://localhost:8081")))
            {
                var endpoint = ((HttpEndpoint)host.Description.Endpoints[0]);  //Assuming one endpoint
                endpoint.TransferMode = TransferMode.Streamed;
                endpoint.MaxReceivedMessageSize = 1024 * 1024 * 10;  // Allow files up to 10MB

                host.Open();
                Console.WriteLine("Host opened at {0} , press any key to end", host.Description.Endpoints[0].Address);
                Console.ReadKey();
            }

我的 web.config 应该如何反映这个配置?或者有没有其他方法可以代替使用 ASP.NET?

任何帮助表示赞赏。

4

1 回答 1

1

如果要保留现有配置,可以将所有配置设置内容放入一个方法中,然后从global.asax Application_Start()方法中调用它。所有 Global.asax 方法都将在 WCF 中被调用,就像它们在 ASP.NET 中一样。

或者,您可以将您的服务连接到自定义ServiceHostFactory并且ServiceHost其中包含所有配置(这是我在当前应用程序中使用的方法)。

于 2011-07-07T20:16:20.173 回答