无法托管WCF服务

时间:2013-04-07 18:41:37

标签: c# .net wcf binding duplex

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

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

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

1 个答案:

答案 0 :(得分:0)

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

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>