gpt4 book ai didi

c# - 如何硬编码WCF配置?

转载 作者:行者123 更新时间:2023-11-30 22:32:13 26 4
gpt4 key购买 nike

我尝试创建硬编码的 wcf 服务(没有 app.config)我尝试了以下内容

service = new CommService.TwService();

localHost = new ServiceHost(service);

ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
localHost.Description.Behaviors.Add(behavior);

localHost.AddServiceEndpoint(typeof(IMetadataExchange),
MetadataExchangeBindings.CreateMexNamedPipeBinding(),
"net.pipe://localhost/service/mex/");

localHost.Open();

失败:

Service 'CommService.TwService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.

最佳答案

您只为 Mex 添加了一个端点,它不会公开服务本身。例如,您需要为服务实现显式添加另一个绑定(bind);

WSHttpBinding binding = new WSHttpBinding();
localHost.AddServiceEndpoint(typeof(CommService.TwService), binding, "http://localhost/service");

关于c# - 如何硬编码WCF配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8832967/

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