[英]WCF: transform programmatic configuration into app.config
我有以下工作编程配置(服务器端)
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 中的配置?
不,除了根据服务类型正确分配配置中的类型/名称......看起来你已经正确完成了,你不应该做任何其他事情来指向配置。
我没有解析配置,但老实说,您可能应该使用配置编辑器工具来设置您的服务。 这可能是导致您的服务无法运行的最小的小错误、错误输入或错过的设置。 我经常说 XML 可能是人类可读的,但它很少是人类可编辑的......而且 IMO WCF 配置属于该阵营:-)
我认为添加 metadatexchange 的 mex 端点可能会解决此问题,但不确定但尝试一次。 或者更好地跟踪服务,在那里您可以找到确切的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.