WCF自托管服务运行ConsoleApp.exe不工作,但在vs2012中运行良好

本文关键字:运行 但在 vs2012 工作 exe 服务 WCF ConsoleApp | 更新日期: 2023-09-27 18:14:59

我有一个noopy问题,如果我运行我自己托管的WCF (WCF服务库+控制台应用程序)服务内VS一切工作正常。如果我想在项目目录中运行consoleapplication.exe,看起来一切都很好,但事实并非如此。(我是c#新手)

我已经测试了

:以管理员身份运行它(关闭和打开防火墙)通过HTTP url

预订我的服务

Works fine意味着我可以远程访问我的服务。工作不正常意味着我不能通过localhost访问它。

是否缺少任何依赖项?

提前感谢!

应用程序。console的配置:

    <system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="NewBehavior">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"
                    policyVersion="Default" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="NewBehavior" name="SampleEmpServiceLib.EmpService">
            <clear />
            <endpoint address="basic" binding="basicHttpBinding" contract="SampleEmpServiceLib.IEmpService"
                listenUriMode="Explicit" />
            <endpoint address="http://localhost:8060/EmpS" binding="wsDualHttpBinding" bindingConfiguration=""
                contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
            <endpoint address="net.tcp://localhost:8888/EmpS" binding="netTcpBinding"
                contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
            <endpoint address="net.pipe://localhost/EmpS" binding="netNamedPipeBinding"
                contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
            <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
                contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:8080/EmpS/" />
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

程序代码。cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using SampleEmpServiceLib;
using System.ServiceModel.Description;
namespace ConsoleApplication
{
class Program
{
    static void Main(string[] args)
    {
        ServiceHost host = new ServiceHost(typeof(EmpService));
        host.Open();
        Console.WriteLine("running on endpoints:");
        foreach (ServiceEndpoint serviceEndpoint in host.Description.Endpoints)
            Console.WriteLine(serviceEndpoint.Address.ToString());
        Console.WriteLine("running");
        Console.ReadLine();
        host.Close();
    }
}

}

WCF自托管服务运行ConsoleApp.exe不工作,但在vs2012中运行良好

我可以建议一些配置更新:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NewBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"
              policyVersion="Default" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="NewBehavior" name="SampleEmpServiceLib.EmpService">
        <clear />
        <endpoint binding="basicHttpBinding" contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
        <endpoint address="dual" binding="wsDualHttpBinding" bindingConfiguration="" contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
        <endpoint binding="netTcpBinding" contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
        <endpoint binding="netNamedPipeBinding" contract="SampleEmpServiceLib.IEmpService" listenUriMode="Explicit" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/EMPS" />
            <add baseAddress="net.tcp://localhost:8888/EMPS" />
            <add baseAddress="net.pipe://localhost/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
相关文章: