我有一个noopy问题,如果我在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>
Program.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();
}
}
}
答案 0 :(得分:1)
我可以建议一些配置更新:
<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>