这是一个noob问题。
我有一个简单的WCF REST服务,非常简单,是从教程构建的。
代码非常少。只是IService1.cs,Service1.svc.cs和我的函数库。
自动生成的web.config非常少。
问题的实质:
MSDN文档like this one在解释web.config文件的各部分如何与/引用代码以及它们如何相互关联/引用时不清楚。
我可以一遍又一遍地阅读文档,但遗憾的是它们并没有帮我实际实现web.config。
我找不到简单解释的文档:
“在您的代码中,您有一个名为/service1/foo
的入口点。因此,在web.config中,您创建一个<service>
,引用/service1/foo
这样......,然后<binding>
条目与此<service>
条目绑定...然后<behavior>
条目与此<service>
条目绑定...
问题(重申):如何将它们挂在一起?
背景 我想开始使用web.config进行限制,如下所述: http://www.danrigsby.com/blog/index.php/2008/02/20/how-to-throttle-a-wcf-service-help-prevent-dos-attacks-and-maintain-wcf-scalability/
但我的web.config甚至没有<system.serviceModel>
部分。
谢谢!
(我应该补充一点,我刚与一位经验丰富的.NET开发人员(7年以上)共进晚餐,他说:“哦,配置文件很糟糕!我从来没有理解过它。我只是在做代码,并将我的设置保存到我自己的设置文件。“)
任何输入或指导表示赞赏!
答案 0 :(得分:2)
请参阅这个很好的入门教程,其中显示了代码如何映射到配置: http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide
可替换地:
如果您的配置中缺少该部分,则可以手动添加该部分。 This链接提供web.config/app.config
的主要部分,用于配置WCF服务。
它解释了您的问题第一部分和第二部分,您可以按照您发布的链接进行操作。
这是我发布的链接部分。
<system.ServiceModel>
<services>
<!—- Define the service endpoints. This section is optional in the new
default configuration model in .NET Framework 4. -->
<service>
<endpoint/>
</service>
</services>
<bindings>
<!-- Specify one or more of the system-provided binding elements,
for example, <basicHttpBinding> -->
<!-- Alternatively, <customBinding> elements. -->
<binding>
<!-- For example, a <BasicHttpBinding> element. -->
</binding>
</bindings>
<behaviors>
<!-- One or more of the system-provided or custom behavior elements. -->
<behavior>
<!-- For example, a <throttling> element. -->
</behavior>
</behaviors>
</system.ServiceModel>