托管在类库中时,Wcf服务无法正常工作 [英] Wcf service is not working when hosted in class library

查看:51
本文介绍了托管在类库中时,Wcf服务无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个用于托管WCF服务的类库。它包含一个app.config。我在可执行文件中使用的库是相同的。

当我尝试将类库作为可执行文件时,它运行正常,服务主机即将出现。

当我引用dll,并尝试做ServiceHost.Open()时出现以下错误:



{Service'ServiceClass'没有应用程序(非基础结构)端点。这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为没有在服务元素中定义端点。}}



我理解dll中的app.config无法访问,我尝试将配置移动到可执行的app.config工作。



有什么方法可以访问dll的app.config。



请帮助



我尝试了什么:



我试过在很多博客中寻找这个问题的解决方案,但是没有具体的解决方案

I am trying to implement a class library which is used to host a WCF service. It is containing a app.config. The same library I have used in a executable.
When I tried making the class library as executable it is running fine, service host is coming up.
When I refer the dll, and try to do ServiceHost.Open() I get following error:

{"Service 'ServiceClass' 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."}

I understood the app.config in dll is not accessible, I tried moving the config to app.config of executable it works.

Is there any way I can access app.config of the dll.

Please Help

What I have tried:

I tried looking for solution to this problem in many blogs, but no concrete solution

推荐答案

而不是通过app.config创建一个端点,你可以在代码中做到这一点 - 类似于:



Rather than creating an endpoint via the app.config, you can do it in code - something along the lines of:

using System.ServiceModel.Description;
.
.
.
Uri baseAddress = new Uri("http://SomePath/MyService.svc");
.
BasicHttpBinding binding = new BasicHttpBinding();
EndpointIdentity identity = EndpointIdentity.CreateDnsIdentity("localhost");
EndpointAddress address = new EndpointAddress(baseAddress, identity);
.
MyService.MyServiceClient client = new MyService.MyServiceClient(binding, address);
client.DoSomething();


这篇关于托管在类库中时,Wcf服务无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆