繁体   English   中英

无法托管WCF服务

[英]Can't host the WCF service

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

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

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

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

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM