服务参考适用于Windows窗体,但不适用于类库

Service reference works for windows form but doesn't work for class library
2021-05-11
  •  译文(汉语)
  •  原文(英语)

我有两个应用程序.其中一个是Windows窗体应用程序,另一个是使用类库的Web应用程序.我使用Web服务(WCF).当我将此Web服务作为对Windows窗体应用程序的服务引用时,一切都很好.但是,当我将其作为类库的服务引用时,出现此错误' No connection could be made because the target machine actively refused it ...'

我对这两个项目的引用方式相同.我该怎么办?

速聊1:
您遵循哪种托管方式?IIS或进程中.它支持哪种绑定?
解决过程1

默认情况下,您无法通过来自类库的配置文件来配置WCF服务.

在Web应用程序程序集中添加web.config具有正确WCF配置(类似于app.configwinforms项目中的WCF配置)的.

速聊1:
您的意思是,我应该将wcf服务而不是类lib添加到我的Web应用程序中?
速聊2:
不可以,您可以将服务引用添加到类lib中,但是服务的配置必须位于可执行程序集(winforms或webapp程序集)中

I have two applications. One of them is a windows forms application and other one is a web application which use a class library. I use a web service(WCF). When I give this web service as service reference to my windows form application everything is fine. But when I give it as service reference to class library, I have this error 'No connection could be made because the target machine actively refused it ...'

I give the reference as the same way to these two projects. What should I do?

Talk1:
What kind of hosting you follow ? IIS or In Process. What kind of binding does it supports ?
Solutions1

By default, you cannot configure your WCF service through a configuration file coming from your class library.

Add a web.config with the proper WCF configuration (similar to the one in the app.config of your winforms project) in your web application assembly.

Talk1:
Do you mean, I should add wcf service to my web app instead of class lib?
Talk2:
No, you can add the service reference to the class lib, but the configuration of the service must be located in the executable assembly (either the winforms or the webapp assembly)
转载于:https://stackoverflow.com/questions/20218014/service-reference-works-for-windows-form-but-doesnt-work-for-class-library

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入