0

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

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

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

1 回答 1

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>
于 2013-04-08T15:14:22.643 回答