我有以下工作编程配置(服务器端)
using (ServiceHost host = new ServiceHost(
typeof(RequestHandler),
new Uri[] { new Uri("net.pipe://localhost") }))
{
NetNamedPipeBinding tBinding = new NetNamedPipeBinding();
host.AddServiceEndpoint(typeof(RequestInterface),
tBinding, "Request");
host.Open();
Application.Run(new Form1());
}
试图把它变成代码app.config
:
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
transactionFlow="false"
transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288"
maxBufferSize="65536"
maxConnections="10"
maxReceivedMessageSize="65536">
<security mode="Transport">
<transport protectionLevel="EncryptAndSign" />
</security>
</binding>
</netNamedPipeBinding>
</bindings>
<services>
<service name="ServerApp.RequestHandler">
<host>
<add baseAddress="net.pipe://localhost/" />
</host>
<endpoint address="net.pipe://localhost/Request/"
binding="netNamedPipeBinding"
contract="AppLib.RequestInterface" />
</service>
</services>
但是,这似乎不起作用——即客户端无法连接到此。
我的 app.config 代码有问题吗?还是我必须以编程方式告诉 .NET 使用 app.config 中的配置?