0

我在让这一切正常运行时遇到了一些麻烦。

这是我的 web.config:

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <bindings>
      <webHttpBinding>
        <binding name="requestSizeMax_1MB" maxReceivedMessageSize="1048576" transferMode="Streamed"></binding>
        <binding name="requestSizeMax_10MB" maxReceivedMessageSize="10485760" transferMode="Streamed"></binding>
        <binding name="requestSizeMax_100MB" maxReceivedMessageSize="104857600" transferMode="Streamed"></binding>
        <binding name="requestSizeMax_1000MB" maxReceivedMessageSize="1048576000" transferMode="Streamed"></binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="http">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="REST.IO.FileHandler">
        <endpoint binding="webHttpBinding" bindingConfiguration="requestSizeMax_1000MB" behaviorConfiguration="http" contract="REST.IO.IFileHandler"/>
      </service>
    </services>

这是我对程序化版本的尝试(在 Global.asax 中):

protected void Application_Start(object sender, EventArgs e) {
  //Dynamically Add Service EndPoint
    Uri baseAddress = new Uri("http://localhost:8000/");
    WebServiceHost serviceHost = new WebServiceHost(typeof(FileHandler), baseAddress);
    WebHttpBinding restBinding = new WebHttpBinding();
    restBinding.MaxReceivedMessageSize = 1048576000;
    restBinding.TransferMode = TransferMode.Streamed;
    ServiceEndpoint restService = serviceHost.AddServiceEndpoint(typeof(IFileHandler), restBinding, "Services/IO/FileHandler");
    restService.Behaviors.Add(new WebHttpBehavior());
    serviceHost.Open();
}

现在这将起作用,但前提是 WebServiceHost 在与网站不同的端口上打开。这与通过 web.config 设置不同。如何获得反映 web.config 功能的编程设置。尝试将其设置为与网站相同的端口将生成“进程无法访问文件,因为它正被另一个进程使用”错误。

我听说你可以覆盖 ServiceHostFactory,但我所有的尝试都失败了。我似乎无法让 WebServiceHost 使用它。ServiceHost 似乎可以工作,但我使用的是以前开发的 REST 服务,我需要通过我们的网站以编程方式托管它,主要是因为它是计划托管的几个服务中的第一个,我需要做这个对于我们需要执行的多个部署尽可能动态。

4

1 回答 1

0

我想知道你可能有什么问题。通过命令式配置公开 WCF 只是设置ServiceHostFactory,将*.svc文件指向工厂并在工厂中创建绑定。

这应该让你开始,我已经写了关于如何为基本的 HTTP 绑定 WCF 配置 SSL 的博客,但总体思路是相同的,你只更改绑定、端点和合同。

http://www.wiktorzychla.com/2010/05/how-to-programmatically-configure-ssl.html

于 2013-12-05T21:38:38.217 回答