WCF 基地址被 App.config 覆盖
WCF Base address overridden by App.config
今天我开始研究 WCF。我在 https://msdn.microsoft.com/en-us/library/ms734712(v=vs.110).aspx
学习了教程
我逐步完成了本教程,直到您托管服务主机为止。教程部分 here told me start up the service and then navigate to the uri specified in code. When I did that my connection was refused. After a short while of messing around, I found that the base address was specified in the app.config as something else entirely. Navigating to that URI followed by the endpoint name took me where I wanted to go. I don't know how that address was generated, and don't really care all that much. What I'm more interested in is what purpose setting the base URI on the services plays when it seemingly has no effect whatsoever, and the actual base URI that is used comes from the app.config. It's required by the constructor of the ServiceHost 输入...所以您会认为它很重要。谁可以给我解释一下这个?
如果仔细观察 ServiceHost
的两个构造函数,它们期望 Uris,Uri 参数以 params
为前缀。
在 C# 中,这意味着您可以传递任意数量的 Uris,包括零个。
如果您想使用 app.config.
的,则不传递 Uri 很有趣
如果没有配置,则传递类型或对象和一些 Uris。
然后 WCF 创建一个服务,该服务在所有 Uris 上公开该服务的所有接口。
例如,如果您的服务中有两个接口,您调用:
var host = new ServiceHost(typeof(HelloService),
"net.tcp://localhost:7000/service1",
"net.pipe://localhost:8000/service1",
"http://localhost:9000/service1");
您将获得 2x3 暴露的端点
大部分时间 ServiceHost
都是在不提供地址的情况下构建的。
配置在 XML.
此致
今天我开始研究 WCF。我在 https://msdn.microsoft.com/en-us/library/ms734712(v=vs.110).aspx
学习了教程我逐步完成了本教程,直到您托管服务主机为止。教程部分 here told me start up the service and then navigate to the uri specified in code. When I did that my connection was refused. After a short while of messing around, I found that the base address was specified in the app.config as something else entirely. Navigating to that URI followed by the endpoint name took me where I wanted to go. I don't know how that address was generated, and don't really care all that much. What I'm more interested in is what purpose setting the base URI on the services plays when it seemingly has no effect whatsoever, and the actual base URI that is used comes from the app.config. It's required by the constructor of the ServiceHost 输入...所以您会认为它很重要。谁可以给我解释一下这个?
如果仔细观察 ServiceHost
的两个构造函数,它们期望 Uris,Uri 参数以 params
为前缀。
在 C# 中,这意味着您可以传递任意数量的 Uris,包括零个。
如果您想使用 app.config.
的,则不传递 Uri 很有趣如果没有配置,则传递类型或对象和一些 Uris。
然后 WCF 创建一个服务,该服务在所有 Uris 上公开该服务的所有接口。
例如,如果您的服务中有两个接口,您调用:
var host = new ServiceHost(typeof(HelloService),
"net.tcp://localhost:7000/service1",
"net.pipe://localhost:8000/service1",
"http://localhost:9000/service1");
您将获得 2x3 暴露的端点
大部分时间 ServiceHost
都是在不提供地址的情况下构建的。
配置在 XML.
此致