首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以编程方式配置ASP.NET承载的WCF 3.5 WebServiceHost?(即没有WebConfig)

以编程方式配置ASP.NET承载的WCF 3.5 WebServiceHost?(即没有WebConfig)
EN

Stack Overflow用户
提问于 2013-12-05 21:31:10
回答 1查看 825关注 0票数 0

我有一点麻烦,让这一切都运行。

这是我的web.config:

代码语言:javascript
复制
  <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中):

代码语言:javascript
复制
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服务,我需要通过我们的网站以编程方式托管它,主要是因为它是计划托管的几个服务中的第一个,而且我需要使它对我们需要执行的多个推出尽可能动态。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-05 21:38:38

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

这应该可以让您开始,我已经在博客中谈到了如何为基本的HTTP绑定WCF配置SSL,但总体思路是相同的,您只需要更改绑定、端点和契约。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20411166

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档