如何在IIS中托管代码时配置WCF服务? [英] How to configure WCF service from code when hosted in IIS?

查看:198
本文介绍了如何在IIS中托管代码时配置WCF服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WCF服务公开了https和http端点。除了SSL,它们是相同的。它们映射到相同的代码。

My WCF service exposes an https AND an http endpoint. Apart from the SSL they are identical. They map to the same code.

最终目的是外部用户通过https连接,内部用户使用http。

The ultimate intention is for external users to connect via https, internal users to use http.

在开发中,这给我一个问题。 Cassini,VS中打包的开发web服务器,讨厌SSL。

In development this gives me a problem. Cassini, the development web server packaged in VS, hates SSL.

我想知道我是否可以从代码配置服务,所以当在Cassini下运行时,配置https。

I'm wondering if I can configure the service from code, so when running under Cassini, I would not configure https.

因此,问题 - 如果是IIS托管,如何从代码配置服务?我会对如何说服Cassini不要抱怨配置的https部分的替代答案感到非常高兴。

Hence the question - How do I configure the service from code if it is IIS hosted? I'd be very happy with alternative answers on how I can persuade Cassini to NOT complain about the https part of the configuration.

推荐答案

当你在IIS中托管时,你会留下很多关心IIS的领域 - 你不能真正抓住你的服务在这种情况下。

When you're hosting in IIS, you're leaving a lot of care taking into the realm of IIS - you cannot really grab a hold of your service in this case.

IIS将根据你的* .svc文件来处理必要的 ServiceHost - 不是真的可以这样做。

IIS will take care of spinning up the necessary ServiceHost based on your *.svc file - not a whole lot you can do about that, really.

我的解决方案会有所不同 - 将您的配置文件( web.config)中的< service> ):

My solution would be different - externalize the <service> tag in your configuration file (web.config):

<system.serviceModel>
  <services>      
     <service configSource="service.dev.config" />
  </services>
</system.serviceModel>

在您的开发环境中,只公开http端点 - 因此您的服务。 dev.config 看起来像这样:

In your dev environment, only expose the http endpoint - so your service.dev.config would look something like this:

<service name=".....">
    <endpoint name="default"
              address="....."
              binding="basicHttpBinding" bindingConfiguration="insecure"
              contract="......" />
</service>

创建第二个 service.prod.config 然后包含两个端点 - http和https:

Create a second service.prod.config which then contains both endpoints - http and https:

<service name=".....">
    <endpoint name="default"
              address="....."
              binding="basicHttpBinding" bindingConfiguration="insecure"
              contract="......" />
    <endpoint name="secure"
              address="....."
              binding="basicHttpBinding" bindingConfiguration="secure"
              contract="......" />
</service>

并引用 web.config 在部署服务器上。

and reference that in your web.config on the deployment server.

这篇关于如何在IIS中托管代码时配置WCF服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆