简体   繁体   English

将WCF服务添加到项目中

[英]Adding a WCF Service to a project

I have a C# WinForms Project which contains some WCF service definition files which I have created in the project by adding standard classes (not using Add Item > WCF Service). 我有一个C#WinForms项目,它包含一些WCF服务定义文件,我在项目中通过添加标准类(不使用Add Item> WCF Service)创建了这些文件。

The project contains some dependencies that require me to build the project for x86 processors. 该项目包含一些依赖项,需要我为x86处理器构建项目。

If I edit the app.config file with the WCF Service Configuration Editor and try to use the "Create New Service ..." wizard, and then browse to the project EXE file (in the debug folder) I get an error, (which I've read is because I'm targeting the x86 processor): 如果我使用WCF服务配置编辑器编辑app.config文件并尝试使用“创建新服务...”向导,然后浏览到项目EXE文件(在调试文件夹中),我收到错误(我读过的是因为我的目标是x86处理器):

Could not load file or assembly 'EXE_FILE_NAME' or one of its dependencies. An attempt was made to load a program with an incorrect format.

So, upon changing the target to All CPUs, compiling the project again, and then trying to create the service in the WCF Service Configuration Editor again, I now get a different error: 因此,在将目标更改为所有CPU,再次编译项目,然后再次尝试在WCF服务配置编辑器中创建服务时,我现在得到一个不同的错误:

Could not load file or assembly 'SOLUTION_NAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

(To clarify, I CAN still compile the project when targeting all CPUs, but get an error at runtime due to a dependency) (为了澄清,我仍然可以在针对所有CPU时编译项目,但由于依赖性而在运行时收到错误)

Is anybody able to help me with this problem, so I can add the services defined in app.config file using the wizards in WCF Service Configuration Editor? 有没有人能够帮我解决这个问题,所以我可以使用WCF服务配置编辑器中的向导添加app.config文件中定义的服务? (I think that if I add the services to the WCF Service Configuration Editor when targeting All CPUs I can make any modifications thereafter, regardless of the target) (我认为,如果我在定位所有CPU时将服务添加到WCF服务配置编辑器,我可以在此后进行任何修改,无论目标是什么)

When debugging, look at the exception detail. 调试时,请查看异常详细信息。 From what you've described my guess is you will an assembly loading error in the fusion log because the dependencies of the WCF service can't be satisfied by looking in the default locations. 根据您的描述,我猜您将在融合日志中出现程序集加载错误,因为查看默认位置无法满足WCF服务的依赖性。

Say for example you're referencing MrCritter.MyService.dll which defines a WCF service and has a dependency on something like log4net or nHibernate. 比如说你正在引用MrCritter.MyService.dll,它定义了一个WCF服务并依赖于log4net或nHibernate之类的东西。 As long as nothing from those dependencies is leaking into the WCF host (eg returning an ILog) yes you'll be able to compile fine but will get ReflectionTypeLoadException thrown when trying to instantiate the service class if those dependencies aren't somewhere it can find (eg in the executing directory, in GAC etc). 只要这些依赖项中没有任何内容泄漏到WCF主机中(例如返回ILog)是的,您将能够编译正常但在尝试实例化服务类时会抛出ReflectionTypeLoadException ,如果这些依赖项不在它可以找到的地方(例如,在执行目录中,在GAC等中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM