我遇到了一个麻烦的问题,如果我在 VS 中运行我的自托管 WCF(WCF 服务 Lib + 控制台应用程序)服务,一切正常。如果我想在项目目录中运行 consoleapplication.exe,看起来一切正常,但事实并非如此。(我是 C# 新手)
我已经测试过:以管理员身份运行它(防火墙关闭和打开)以通过 http urlacl 保留我的服务
工作正常意味着我可以远程访问我的服务。工作不正常意味着我不能通过 localhost 访问它。
是否缺少任何依赖项?
先感谢您!
consoleApp的App.config:
<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();
}
}
}