WCF:将编程配置转换为 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 中的配置?
I have the following working programmatic configuration (server-side)
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());
}
trying to turn this into code for 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>
However, this doesn't seem to work - i.e. clients can not connect to this.
Do I have something wrong in my app.config code?
Or do I have to something programmatically to tell .NET to use the configuration from app.config?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,除了根据服务类型在配置中正确分配类型/名称之外......看起来您已经正确完成了,您不必执行任何其他操作来指向配置。
我没有解析配置,但说实话,您可能应该使用 配置编辑器用于设置您的服务的工具。这可能是导致您的服务无法工作的最小错误、错误输入或错过设置。我经常说 XML 可能是人类可读的,但它很少是人类可编辑的......并且 IMO WCF 配置属于这个阵营:-)
No, aside from properly assigning the type/name in the config based on the service type ... which it looks like you've done correctly, you shouldn't have to do anything else to point to the configuration.
I didn't parse through the config, but honestly, you should probably use the Configuration Editor Tool to set up your service. It's probably the smallest little error, or mistype, or missed setting that's causing your service not to work. I've often said that XML may be human readable, but it's rarely human editable ... and IMO WCF configuration falls into that camp :-)
我认为添加 metadatexchange 的 mex 端点可能会解决这个问题,不确定,但尝试一次。
或者最好跟踪服务,在那里您可以找到确切的问题。
I think adding a mex endpoint of metadatexchange may resolve this, not sure but try it once.
or its better you on the trace for service where you can find out exact problem.