尝试找出我的 WCF 服务无法运行的原因

发布于 2024-11-05 08:47:06 字数 2020 浏览 4 评论 0原文

一年多前,我一直在开发 WCF 服务,该服务是我使用 VS 2008 编写的。它运行在 Windows 服务下,这也是我编写的。从那时起它就一直在那里运行。不幸的是,其他项目/优先事项已经出现,阻止我继续该项目,直到现在。

现在我正试图回到它。然而,我试图找出是否可以使用 VS 2010 和 .NET 4,而不是 .NET 3.5。我打开了命令提示符,运行 SvcUtil,获取 wsdl 信息,我将把这些信息放入我正在尝试开始编写的新 WPF 应用程序的配置文件中。唯一的问题是,我不断收到错误,说我无法访问服务器等。

因此,我将 .exe.config 文件从服务器复制到我的计算机,我可以在其中使用 SvcConfigEditor 编辑它。我已经进行了这些更改,将其放回到服务器上,并在尝试运行 SvcUtil 时遇到错误,但更糟糕的是我没有看到我期望看到的 .svclog 文件。所以我进入了服务器的服务应用程序。找到了我一年前写的Windows服务;看到它正在运行,就停下来再启动。

现在我有一个不同的问题。我的 Windows 服务启动,但随后立即停止。我收到这条消息,说该服务已启动然后停止,并说有时不同类型的服务会发生这种情况,例如性能日志和警报服务。我检查了服务器上的事件日志,与此Windows服务唯一相关的是它进入了启动状态,然后进入了停止状态。

啊,在尝试启动它四次之后,它终于在事件日志中给了我一个错误! (为什么它一开始不这样做?谁说尝试一遍又一遍地做同样的事情,并期待不同的结果是疯狂的标志,而显然前 3 次它没有记录任何东西在事件日志中,但在第四次尝试时确实如此。)

这是错误:

事件类型:错误 事件来源:Service1 活动类别:无 事件ID:0 日期:2011 年 5 月 4 日 时间:上午 10:14:46 用户:不适用 电脑:赫利俄斯 描述: 服务无法启动。系统类型初始化异常: “System.ServiceModel.DiagnosticUtility”的类型初始值设定项 抛出异常。 --->System.Configuration.ConfigurationErrorsException:找不到类型 对于类 System.Diagnostics.XmlWriterTraceListener,系统,版本=4.0.0.0, 文化=中立,PublicKeyToken=b77a5c561934e089。 在 System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, 字符串初始化数据)

下面是 SvcConfigEditor 放入 .config 文件中的新代码部分:

<sharedListeners>
<add initializeData="C:\Program Files\ASIWindowsService\ASIWindowsService_tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\Program Files\ASIWindowsService\ASIWindowsService_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>

Over a year ago I had been working on a WCF service, which I wrote using VS 2008. It runs under a Windows service, which I also wrote. It’s been running there ever since. And unfortunately, other projects/priorities have come up, preventing me from continuing with that project, until now.

Now I’m trying to get back to it. However, this go around I’m trying to find out if I can use VS 2010 and .NET 4, instead of .NET 3.5. I’ve brought up the command prompt, to run SvcUtil, to get the wsdl information, which I’ll put into the config file for the new WPF app I’m trying to get started writing. Only thing is, I keep getting an error, saying that I can’t reach the server, etc.

So, I copied the .exe.config file from the server to my machine, where I could edit it with SvcConfigEditor. I’ve made those changes, put it back onto the server, and got an error while trying to run SvcUtil, but worse than that I didn’t see the .svclog files I expected to see. So I got into the server’s Services app. I found the Windows service I wrote a year ago; saw that it was running, and stopped and started it again.

Now I’ve got a different problem. My Windows service starts, but then stops immediately. I get this message saying that the service had started and then stopped, and saying that sometimes that happens with different sorts of services, like Performance Logs and Alerts services. I’ve checked the event log on the server, and then only thing there related to this Windows service is that it entered the start state and then entered the stopped state.

Ah, after attempting to start it 4 times, it finally gave me an error in the event log! (Why didn’t it do that in the first place? And who says that trying to do the same thing over and over again, and expecting different results is a sign of insanity, when clearly the first 3 times it didn’t register anything in the event log, but on the 4th try it did.)

Here’s the error:

Event Type: Error
Event Source: Service1
Event Category: None
Event ID: 0
Date: 5/4/2011
Time: 10:14:46 AM
User: N/A
Computer: HELIOS
Description:
Service cannot be started. System.TypeInitializationException:
The type initializer for 'System.ServiceModel.DiagnosticUtility'
threw an exception. --->System.Configuration.ConfigurationErrorsException: Couldn't find type
for class System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089.
at System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType,
String initializeData)

and here’s the new section of code put into the .config file by SvcConfigEditor:

<sharedListeners>
<add initializeData="C:\Program Files\ASIWindowsService\ASIWindowsService_tracelog.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\Program Files\ASIWindowsService\ASIWindowsService_messages.svclog"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为一人 2024-11-12 08:47:06

这个问题已在评论中得到解答,但我在 Visual Studio 2010 中看到了一个可能导致类似情况的问题。

即使 WCF 项目的目标框架设置为版本 3.x,使用 2010 SvcConfigEditor 也会自动插入“System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0...”,尽管它应该插入“System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0...”。 Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0..." 将更改后的 web.config 部署到托管的 IIS 时,这会困扰您AppPool配置为使用 .NET 4.0 框架的服务。解决方法是将 web.config 编辑回“Version=2.0.0.0”。

This question was answered in the comments but there is a gotcha that I've seen in Visual Studio 2010 that could result in a similar situation.

Even if the target framework is set to version 3.x for a WCF project, using the 2010 SvcConfigEditor will automatically insert "System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0..." although it should be inserting "System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0..." This will bite you when deploying the altered web.config to an IIS hosted service where the AppPool is not configured to use the .NET 4.0 framework. The fix is simply edit the web.config back to "Version=2.0.0.0".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文