服务具有零个应用程序(非基础设施)端点
我最近创建了一个WCF服务(dll)和一个服务主机(exe)。我知道我的 WCF 服务工作正常,因为我能够成功地将服务添加到 WcfTestClient。
但是,当我从服务主机(exe)使用 WCF 时,我似乎遇到了问题。我可以将对 WCF (dll) 的引用添加到我的服务主机 (exe),并为 exe 创建必要的组件;例如服务安装程序、服务主机和app.config,编译并最终使用InstallUtil安装exe。但是,当我尝试在 Microsoft 管理控制台中启动该服务时,该服务在启动后立即停止。
因此,我开始调查到底是什么导致了此问题,并从事件查看器中的应用程序日志中发现了此错误。
描述:
服务无法启动。 系统.InvalidOperationException: 服务‘服务’应用为零 (非基础设施)端点。这 可能是因为没有配置文件 已找到适合您的应用程序的信息,或者 因为没有服务元素匹配 服务名称可以在 配置文件,或者因为没有 端点在服务中定义 元素。
这个错误实际上是在OnStart
中产生的;当我执行此调用 ServiceHost.Open()
时,我的 exe 的。我看过很多其他人也遇到过这个问题的帖子,但是大多数(如果不是全部)都声称服务名称或合同;未指定名称空间和类名。我在我的配置文件中检查了这两个条目;在 exe 和 dll 中,它们完美匹配。我让办公室里的其他人在我身后仔细检查,以确保我没有在某一时刻变得盲目,但当然他们得出了与我相同的结论,一切看起来都指定正确。我真的不知道此时发生了什么。有人可以帮我解决这个问题吗?
发生这种情况的另一个可能原因是 app.config 从未被读取;至少不是我认为应该阅读的一本。这可能是问题所在吗?如果是这样,我该如何解决这个问题。再次强调,任何帮助将不胜感激。
I recently created a WCF service (dll) and a service host (exe). I know my WCF service is working correctly since I am able to successfully add the service to WcfTestClient.
However, I seem to be running into an issue when I comes to utlizing my WCF from a service host (exe). I can add a reference to the WCF (dll) to my service host (exe) and create the necessary componets to the exe; such as the service installer, service host, and the app.config, compile and then finally install the exe using InstallUtil. But, when I tried to start the service in the Microsoft Management Console, the service immediately stops after being started.
So I began investigating what could exactly be causing this issue an came up with this error from the Application Log in the Event Viewer.
Description:
Service cannot be started.
System.InvalidOperationException:
Service 'Service' has zero application
(non-infrastructure) endpoints. This
might be because no configuration file
was found for your application, or
because no service element matching
the service name could be found in the
configuration file, or because no
endpoints were defined in the service
element.
This error is actually generated in the OnStart
; of my exe, when I perform this call ServiceHost.Open()
. I've seen numerous posts where other individuals have run into this issue, however most if not all of them, claim that the service name or contract; namespace and class name, are not being specified. I checked both of these entries in my config file; in the exe as well as in the dll, and they match up PERFECTLY. I've had other people in the office double check behind me to make sure I wasn't going blind at one point, but of course they came to the same conclusion as me that everything looked like it was specified correctly. I am truly at a lost as to what is going on at this point. Could anyone help me with this issue?
Another thing that came up as a possible reason this may be happening is that the app.config is never being read; at least not the one I think should be getting read. Could this be the issue? If so, how can I go about addressing this issue. Again, ANY help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
我刚刚遇到了这个问题,并通过将命名空间添加到服务名称来解决它,例如
,
我也看到它通过 Web.config 而不是 App.config 解决了。
I just had this problem and resolved it by adding the namespace to the service name, e.g.
became
I've also seen it resolved with a Web.config instead of an App.config.
端点还应该具有命名空间:
The endpoint should also have the namespace:
只需将 App.config 文件从服务项目复制到控制台主机应用程序并粘贴到此处,然后从服务项目中将其删除。
Just copy the App.config file from the service project to the console host application and paste here and then delete it from the service project.
需要考虑的一件事是:您的 WCF 是否与 WindowsService (WS) 完全脱钩? WS 很痛苦,因为您对它们没有太多的控制或可见性。我尝试通过将所有非 WS 内容放在自己的类中来缓解这种情况,以便可以独立于主机 WS 进行测试。使用这种方法可能会帮助您消除 WS 运行时与您的服务之间发生的任何问题。
约翰可能是正确的,这是一个 .config 文件问题。 WCF 将始终查找执行上下文.config。因此,如果您在不同的执行上下文中托管 WCF(即,使用控制台应用程序进行测试,并使用 WS 进行部署),则需要确保将 WCF 配置数据移至正确的 .config 文件。但对我来说,根本问题是你不知道问题是什么,因为 WS 粘性阻碍了。如果您还没有重构到可以在任何上下文(即单元测试或控制台)中运行服务,那么我建议您这样做。如果您在单元测试中启动服务,它可能会像您在 WS 中看到的那样失败,这比尝试使用令人讨厌的 WS 管道更容易调试。
One thing to think about is: Do you have your WCF completely uncoupled from the WindowsService (WS)? A WS is painful because you don't have a lot of control or visibility to them. I try to mitigate this by having all of my non-WS stuff in their own classes so they can be tested independently of the host WS. Using this approach might help you eliminate anything that is happening with the WS runtime vs. your service in particular.
John is likely correct that it is a .config file problem. WCF will always look for the execution context .config. So if you are hosting your WCF in different execution contexts (that is, test with a console application, and deploy with a WS), you need to make sure you have WCF configuration data moved over to the proper .config file. But the underlying issue to me is that you don't know what the problem is because the WS goo gets in the way. If you haven't refactored to that yet so that you can run your service in any context (that is, unit test or console), then I'd sugget doing so. If you spun your service up in a unit test, it would likely fail the same way that you are seeing with the WS which is much easier to debug rather than attempting to do so with the yucky WS plumbing.
当我以编程方式添加它时,我收到了更详细的异常 -
AddServiceEndpoint
:I got a more detailed exception when I added it programmatically -
AddServiceEndpoint
:为 WCF 准备配置很困难,有时服务类型定义会被忽视。
我只在服务标签中写了命名空间,所以我得到了同样的错误。
不要忘记,服务标记需要完全限定的服务类名称。
对于其他像我一样的人。
To prepare the configration for WCF is hard, and sometimes a service type definition go unnoticed.
I wrote only the namespace in the service tag, so I got the same error.
Do not forget, the service tag needs a fully-qualified service class name.
For the other folks who are like me.
今天我遇到了同样的问题,在这里发布我的错误并更正它,以便它可以帮助某人。
在重构代码时,我实际上更改了服务类和 IService 名称,并将 ServiceHost 更改为指向这个新的服务类名称(如代码片段所示),但在我的主机应用程序 App.Config 文件中,我仍然使用旧的服务类名称(参考下面代码片段中的配置部分的名称字段)
这是代码片段,
在 App.config 文件中的服务部分下,我指的是旧的服务类名称,将其更改为新的 ServiceClassName 为我解决了问题。
Today i ran into same issue, posting here my mistake and correction of it so that it may help someone.
While Re-structuring code, I had actually changed Service class and IService names and changed ServiceHost to point to this new Service class name (as shown in code snippet) but in my host applications App.Config file i was still using old Service class name.(refer config section's name field in below snippet)
Here is the code snippet,
and in App.config file under section services i was referring to old serviceclass name , changing it to New ServiceClassName fixed issue for me.
我也有同样的问题。一切都在 VS2010 中运行,但是当我在 VS2008 中运行相同的项目时,我得到了提到的异常。
为了使其正常工作,我在 VS2008 项目中所做的就是添加对 ServiceHost 对象的
AddServiceEndpoint
成员的调用。这是我的代码片段:
我没有修改 app.config 文件。但我猜想服务端点也可以添加到 .config 文件中。
I had the same problem. Everything works in VS2010 but when I run the same project in VS2008 I get the mentioned exception.
What I did in my VS2008 project to make it work was adding a call to the
AddServiceEndpoint
member of my ServiceHost object.Here is my code snippet:
I didn't modify the app.config file. But I guess the service endpoint could also have been added in the .config file.
我刚刚遇到这个问题并检查了上述所有答案,以确保我没有遗漏任何明显的内容。好吧,我有一个半明显的问题。我在代码中的类名的大小写与我在配置文件中使用的类名不匹配。
例如:如果类名为 CalculatorService
配置文件引用Calculatorservice ...
你会得到这个错误。
I just ran into this issue and checked all of the above answers to make sure I wasn't missing anything obvious. Well, I had a semi-obvious issue. My casing of my classname in code and the classname I used in the configuration file didn't match.
For example: if the class name is CalculatorService
and the configuration file refers to Calculatorservice ...
you will get this error.
我刚刚在我的服务中解决了这个问题。这是我收到的错误:
以下是我用来修复它的两个步骤:
使用正确的完全限定类名:
使用 mexHttpBinding 启用端点,最重要的是,使用 IMetadataExchange 合约:
I just worked through this issue on my service. Here is the error I was receiving:
Here are the two steps I used to fix it:
Use the correct fully-qualified class name:
Enable an endpoint with mexHttpBinding, and most importantly, use the IMetadataExchange contract:
如果 WCF 服务的托管应用程序的配置文件没有具有正确的配置,就会出现此错误。
记住配置中的这条注释:
如果您有一个托管在 IIS 中的 WCF 服务,则在运行时通过 VS.NET 它将读取服务库项目的 app.config,但部署后会读取主机的 web.config。如果 web.config 没有相同的
配置,您将收到此错误。确保在完善后从 app.config 复制配置。This error will occur if the configuration file of the hosting application of your WCF service does not have the proper configuration.
Remember this comment from configuration:
If you have a WCF Service hosted in IIS, during runtime via VS.NET it will read the app.config of the service library project, but read the host's web.config once deployed. If web.config does not have the identical
<system.serviceModel>
configuration you will receive this error. Make sure to copy over the configuration from app.config once it has been perfected.我在管理员模式下运行 Visual Studio,它对我有用:)
另外,请确保用于编写 WCF 配置的 app.config 文件必须位于使用“ServiceHost”类的项目中,而不是实际的 WCF 服务项目中。
I ran Visual Studio in Administrator mode and it worked for me :)
Also, ensure that the app.config file which you are using for writing WCF configuration must be in the project where "ServiceHost" class is used, and not in actual WCF service project.
我的问题是,当我将 .svc 文件的默认 Service1 类重命名为更有意义的名称时,这导致 web.config 行为配置和端点对应于旧的命名约定。尝试修复您的 web.config。
My problem was when I renamed my default Service1 class for .svc file to a more meaningful name, which caused web.config behaviorConfiguration and endpoint to correspond to old naming convention. Try to fix your web.config.
对于使用控制台应用程序来托管 WCF 服务的人来说,要记住的一件重要事情是 WCF 项目中的 Web.config 文件将被完全忽略。如果您的
system.serviceModel
配置在那里,那么您需要将该配置部分移动到控制台项目的 App.config 中。这是关于确保在正确的位置指定名称空间的答案的补充。
One crucial thing to remember for those working with a Console application to host the WCF service is that the Web.config file in the WCF project is completely ignored. If your
system.serviceModel
configuration is there, then you need to move that section of config to the App.config of your Console project.This is in addition to the answers concerning ensuring the namespace is specified in the right places.
作为另一个线索,这确实解决了我的案例中的这个问题。
我正在将一些 WCF 服务从控制台应用程序(在代码中配置少量 WCF 服务)迁移到 Azure WebRole 以在 Azure 中发布它们。每次我添加一个新服务时,VS 都会编辑我的 web.config 并添加这一行:
嗯,有了上面的所有建议和答案,我无法让它工作,直到我删除了 serviceHostingEnvironment 元素中的所有属性。正如您所看到的,我不是 WCF 明星,但我只需将第一个服务配置为即可使其与第一个服务一起使用:
但是当我添加第二个服务时,它停止工作,我意识到这些属性又出现了。
我希望它可以节省您的时间。
As another clue, that indeed fixed this issue in my case.
I'm migrating some WCF services from a console application (that configures in code few WCF services) to an Azure WebRole to publish them in Azure. Every time I add a new service VS edits my web.config and adds this line:
Well, with all the advices and answers above I couldn't make it work until I removed all the attributes in the serviceHostingEnvironment element. As you can see I'm not a WCF rockstar but I made it to work with the first Service just by configuring it as:
but when I added the second Service it stoped working and I realized that those attributes where there again.
I hope it saves you time.
当我创建的 WCF 服务库未连接进行托管,但已连接进行连接时,我在 Windows 服务中遇到此错误。我错过了一个终点。 (我希望在我的 Windows 服务中同时提供连接和托管,以便我可以向其他连接提供 WCF 服务,并且让我的 Windows 服务的主进程也使用它来执行计时器/计划上的各种任务。)
修复方法是我右键单击 App.config 文件并选择“编辑 WCF 配置”。然后,我执行了创建服务的步骤,以便可以连接到我的 WCF 服务。现在我的 App.config 中有两个端点,而不仅仅是一个。一个端点用于连接到 WCF 服务库,另一个端点用于托管它。
I had this error in a Windows Service when my WCF Service Library that I created was not connected for hosting, but was connected for connection. I was missing an endpoint. (I wanted both connection and hosting in my Windows Service so that I could serve up the WCF Service to other connections, as well as have the main process of my Windows Service use it as well to do various tasks on a timer/schedule.)
The fix was that I rightlcicked my App.config file and chose Edit WCF Configuration. Then, I did the steps for Create Service so that I could connect to my WCF Service. Now I had two endpoints in my App.config, not just one. One endpoint was for the connection to the WCF Service Library, and another was for the hosting of it.
正如其他人提到的,我的问题是我的托管应用程序的 app.config 中没有
system.serviceModel
。例如:As others have mentioned, my problem was that I didn't have the
system.serviceModel
in my hosting application's app.config. For example: