C# 无法启动基于tcp的WCF服务
我正在开发一个基于tcp的WCF服务,在尝试在主机应用程序中启动该服务时,我遇到了这个臭名昭著的WCF异常: System.ServiceModel.dll中发生类型为“System.InvalidOperationException”的未处理异常 其他信息:服务“WcfServiceWas.MathService”没有应用程序(非基础结构)终结点。这可能是因为找不到应用程序的配置文件,或者是因为在配置文件中找不到与服务名称匹配的服务元素,或者是因为在服务元素中未定义端点 这个问题以前被描述过很多次,建议的解决方案是按照类库中定义的方式来命名服务,问题是这个解决方案不适合我 托管服务拒绝启动服务的配置有什么问题 服务接口(IMathService.cs): 服务实现(MathService.cs): Svc文件(MathService.Svc):C# 无法启动基于tcp的WCF服务,c#,.net,web-services,wcf,tcp,C#,.net,Web Services,Wcf,Tcp,我正在开发一个基于tcp的WCF服务,在尝试在主机应用程序中启动该服务时,我遇到了这个臭名昭著的WCF异常: System.ServiceModel.dll中发生类型为“System.InvalidOperationException”的未处理异常 其他信息:服务“WcfServiceWas.MathService”没有应用程序(非基础结构)终结点。这可能是因为找不到应用程序的配置文件,或者是因为在配置文件中找不到与服务名称匹配的服务元素,或者是因为在服务元素中未定义端点 这个问题以前被描述过很
更新:托管应用程序的app.config也必须包含wcf配置。您需要在
下定义绑定部分,添加以下
配置:
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfiguration" sendTimeout="00:01:00">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
编辑这行
,谢谢你的回答,我以前试过配置绑定(实际上,根据文档,你不必拥有它)。我尝试了你的解决方案,但不幸的是,没有为我做任何事情。看,我创建了一个新的wcf服务,起初我得到了你的确切错误,然后我将配置部分从wcf服务的web.config移到了服务主机的app.config,它成功了。尝试此操作并让我知道。更改主机应用的app.config有效-因此配置正常,只是没有考虑到。如果你改变你的答案,我会接受的。谢谢
namespace WcfServiceWas
{
public class MathService : IMathService
{
public OperationResult Add(int x, int y)
{
return new OperationResult { Result = new MyInteger { Value = x + y } };
}
public int Subtract(int x, int y)
{
return x - y;
}
}
}
<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceWas.MathService" CodeBehind="MathService.cs" %>
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceWas.MathServiceBehavior" >
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfServiceWas.MathService" behaviorConfiguration="WcfServiceWas.MathServiceBehavior" >
<endpoint contract="WcfServiceWas.IMathService" binding="netTcpBinding" address="" />
<endpoint contract="IMetadataExchange" binding="mexTcpBinding" address="mex" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:999/MathServiceX/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
class Program
{
static void Main(string[] args)
{
using (var myServiceHost = new ServiceHost(typeof(MathService)))
{
myServiceHost.Open();
}
}
}
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfiguration" sendTimeout="00:01:00">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<endpoint contract="WcfServiceWas.IMathService"
binding="netTcpBinding"
bindingConfiguration="netTcpBindingConfiguration"
address="" />