如何在 app.config 的 xml 服务声明中读取 appseting 键
我正在 VS 2010 和 .NET 4.0 中开发 WCF 服务。
我正在创建 app.config 文件,我想指定一次服务器的基地址。
我已将其声明到 appConfig 部分中:
<appSettings>
<add key="base_address" value="net.tcp://localhost:5050/Service1/"/>
</appSettings>
我想知道如何将该密钥引用到 service/host/baseaAddressses 中,例如:
<service
name="WcfService_callbacks_tcp_auth_username.Service1"
behaviorConfiguration="beh_auth">
<host>
<baseAddresses>
<add baseAddress="!!!here_the_key!!!"/>
</baseAddresses>
</host>
</service>
在客户端/端点部分中,例如:
<client>
<endpoint address="!!!here_the_key!!!" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="Service1.IService1"
name="NetTcpBinding_IService1">
<identity>
<certificate encodedValue="..." />
</identity>
</endpoint>
</client>
是否有办法执行此操作?
谢谢。
I am developing a WCF Service in VS 2010 and .NET 4.0.
I am creating the app.config file and I want to specify once the base address for the server.
I've declared it into the appConfig section as:
<appSettings>
<add key="base_address" value="net.tcp://localhost:5050/Service1/"/>
</appSettings>
I would like to know how can I reference that key into the service/host/baseaAddressses like:
<service
name="WcfService_callbacks_tcp_auth_username.Service1"
behaviorConfiguration="beh_auth">
<host>
<baseAddresses>
<add baseAddress="!!!here_the_key!!!"/>
</baseAddresses>
</host>
</service>
And in the client/endpoint section like:
<client>
<endpoint address="!!!here_the_key!!!" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="Service1.IService1"
name="NetTcpBinding_IService1">
<identity>
<certificate encodedValue="..." />
</identity>
</endpoint>
</client>
Is there anyway to do this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能开箱即用地这样做。
您可以在 WCF 配置中显式指定基地址
,也可以从代码中的
app.config
读取它并在 WCF 代码中设置它(客户端示例 - 在服务端,您需要调用ServiceHost
上的.AddServiceEndpoint()
):您无法在
app.config
中引用其他配置设置 - .NET 配置系统不会这样做支持这一点。You cannot do that out of the box.
Either you specify the base address explicitly in your WCF config
or you read it from the
app.config
in code and set it in WCF code (sample for client side - on the service side, you need to call.AddServiceEndpoint()
on yourServiceHost
):You cannot reference another config settings inside
app.config
- the .NET config system just doesn't support that.