gpt4 book ai didi

wcf - 在服务和客户端之间共享 WCF 设置

转载 作者:行者123 更新时间:2023-12-02 00:43:11 24 4
gpt4 key购买 nike

WCF 服务和客户端是否可以共享关于绑定(bind)等的相同设置(来自相同的配置文件),无论在什么情况下?换句话说,我是否可以编写一个绑定(bind)部分并放入任何内容并确保它对服务和客户都有好处?

我会更好地解释。我有一个这样的配置文件:

<services>
<service name="TestClass1">
<endpoint binding="basicHttpBinding" address="http://dev00:4322/host1/TestApplication1" contract="myApp.Interface.ITestApplication"/>
<endpoint binding="netTcpBinding" bindingConfiguration="Binding1" address="net.tcp://dev00:4321/host1/TestApplication1" contract="myApp.Interface.ITestApplication"/>
<endpoint binding="netNamedPipeBinding" address="net.pipe://localhost/host1/TestApplication1" contract="myApp.Interface.ITestApplication"/>
</service>

<service name="ManagementClass1">
<endpoint binding="netNamedPipeBinding" address="net.pipe://localhost/host1/ManagementApplication1" contract="myApp.Interface.IManagementApplication"/>
<endpoint binding="netTcpBinding" bindingConfiguration="Binding1" address="net.tcp://dev00:4321/host1/ManagementApplication1" contract="myApp.Interface.IManagementApplication"/>
</service>
</services>

<client>
<endpoint name="clientTestClass1Tcp"
address="net.tcp://dev00:4321/host1/TestApplication1"
binding="netTcpBinding"
bindingConfiguration="Binding1"
contract="myApp.Interface.ITestApplication"/>

<endpoint name="clientManagementClass1Tcp"
address="net.tcp://dev00:4321/host1/ManagementApplication1"
binding="netTcpBinding"
bindingConfiguration="Binding1"
contract="myApp.Interface.IManagementApplication"/>
</client>

<bindings>
<netTcpBinding>
<binding name="Binding1"
closeTimeout="00:00:10"
openTimeout="00:00:10"
receiveTimeout="00:01:00"
sendTimeout="00:01:00"
transactionFlow="false"
transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard"
listenBacklog="10"
maxBufferPoolSize="524288"
maxBufferSize="65536"
maxConnections="30"
maxReceivedMessageSize="65536">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>

并非一切都在我的控制之下。我可以确定在服务和客户端之间共享绑定(bind)(和其他部分..),无论编写什么,在服务和客户端中都运行良好吗?

最佳答案

是的,您可以 - 在某种程度上:

  • 将您的绑定(bind)、行为、扩展信息放入单独的配置文件中
  • 从应用程序的客户端和服务器部分引用它们

即把你的绑定(bind)放在 bindings.config :

<?xml version="1.0" encoding="utf-8"?>
<bindings>
<basicHttpBinding>
<binding name="Default" useDefaultWebProxy="false">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"
proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>

然后从您服务的 app.config 或 web.config 中引用该文件:

<system.serviceModel>
<bindings configSource="bindings.config" />
</system.serviceModel>

Visual Studio 会提示“configSource”——但相信我,它是有效的。这是用于验证的 Visual Studio XML 架构中的一个缺陷 - 但该功能有效。这实际上适用于您的 web.config/app.config 中的任何配置部分(但不适用于配置部分组)。

您可以对 <system.serviceModel> 的任何“小节”执行此操作配置组 - 客户端、服务器、行为、扩展,应有尽有。

马克

关于wcf - 在服务和客户端之间共享 WCF 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1908237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com