【问题标题】:Can't host the WCF service无法托管 WCF 服务
【发布时间】:2013-04-07 18:41:36
【问题描述】:

我有带有 wsDualHttpBinding 的 WCF 服务。 如何在托管应用程序中托管它?

Uri baseAddress = new Uri("http://localhost:51160");

using (ServiceHost host = new ServiceHost(typeof(FileServer), baseAddress))
{
    host.Open();
    Console.ReadLine();
    host.Close();
}

【问题讨论】:

  • 你得到什么错误?如果这是权限问题,请确保以管理员权限运行它。如果您从 Visual Studio 调试您的应用程序,您必须专门以管理员身份运行 IDE。
  • 合约需要双工,但绑定 'basicHttpBinding' 不支持
  • 这个错误似乎有2630 search results,你看过那些吗?
  • 我做到了。问题是如何为主机设置绑定。
  • This 应该这样做。

标签: c# .net wcf binding duplex


【解决方案1】:

解决方案是将端点添加到我的服务:

Uri baseAddress = new Uri("http://localhost:51160");
WSDualHttpBinding binding = new WSDualHttpBinding();
using (ServiceHost host = new ServiceHost(typeof(FileServer), baseAddress))
{
    host.AddServiceEndpoint(typeof(IFileServer), binding, "http://localhost:51160/FileServer");

    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    host.Description.Behaviors.Add(smb);

    host.Open();
    Console.ReadLine();
    host.Close();
}

在服务器端也一样(在配置中)

<services>
  <service name="AK3_Server.FileServer" behaviorConfiguration="FileServerBehavior">
    <endpoint address="http://localhost:51160/FileServer" binding="wsDualHttpBinding"
      bindingConfiguration="" contract="AK3_Server.IFileServer" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="FileServerBehavior">          
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>          
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

【讨论】:

  • 嗨,伙计,你重复做同样的事情,你只需要使用配置文件或通过 C# 代码配置它.. 不是从两个地方.. 把 app.config 中的内容放在评论中它仍然会工作
猜你喜欢
  • 2013-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-18
相关资源
最近更新 更多