Abp Wcf结合使用问题

在学习了几天的Abp后,大概是对Abp有了一个印象较为简单的记忆。由于以前接触过DDD相关内容,故学习起来比较顺利。

然而在搭建Wcf服务时候还是出现个各种Bug...

1.No component for supporting the service Abp.Web.Localization.ICurrentCultureSetter was found...

这个问题在AbpGithub上也有人提。解决方案也简单。就是在WcfModule里添加对Apb模块AbpWebApiModule的注入。

Github链接https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2463

2.在服务.svc文件中无法将Application接口注入。

  •   Kernel was null, did you forgot to call DefaultServiceHostFactory.RegisterContainer() ?参数名: kernel
    在Global文件加入代码
            protected override void Application_Start(object sender, EventArgs e)
            {  AbpBootstrapper.IocManager.IocContainer.AddFacility<WcfFacility>()
                    .Register(
                        Component.For<ErrorHandlerBehavior>().Attribute("scope").Eq(WcfExtensionScope.Services)
                    );
    
                base.Application_Start(sender, e);
            }
  • 提供的服务类型无法加载为服务,因为它没有默认(缺少参数)构造函数。要解决此问题,请将默认构造函数添加到类型或将类型的实例传递到主机。
    在你建立的.svc服务文件中添加Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory,Castle.Facilities.WcfIntegration"这个是Abp自带的Castle注入工厂。

     同时在WcfModule中进行Wcf服务注入。示例

 1 using Abp.Modules;
 2 using Abp.WebApi;
 3 using Castle.Facilities.WcfIntegration;
 4 using Castle.MicroKernel.Registration;
 5 using System;
 6 using System.Collections.Generic;
 7 using System.Linq;
 8 using System.Reflection;
 9 using System.ServiceModel;
10 using System.Text;
11 using System.Threading.Tasks;
12 using Try.Wcf2;
13 
14 namespace Try
15 {
16     [DependsOn(typeof(TryApplicationModule), typeof(TryCoreModule), typeof(TryDataModule),typeof(AbpWebApiModule))]
17     public class TryWcfModule : AbpModule
18     {
19         public override void Initialize()
20         {
21             IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
22 
23             InitServices();
24         }
25 
26         /// <summary>
27         /// 注册WCF服务
28         /// </summary>
29         private void InitServices()
30         {
31             var basicHttpBinding = new BasicHttpBinding()
32             {
33                 MaxBufferPoolSize = 2147483647,
34                 MaxBufferSize = 2147483647,
35                 MaxReceivedMessageSize = 2147483647,
36             };
37 
38             var webHttpBinding = new WebHttpBinding()
39             {
40                 MaxBufferPoolSize = 2147483647,
41                 MaxBufferSize = 2147483647,
42                 MaxReceivedMessageSize = 2147483647,
43             };
44 
45             IocManager.IocContainer.Register
46                 (
47                      Component.For<IStudentService>()
48                      .ImplementedBy<StudentService>()
49                      .Named("StudentService")
50                      .AsWcfService(new DefaultServiceModel().AddEndpoints(WcfEndpoint.BoundTo(basicHttpBinding)).Hosted().PublishMetadata())
51                 );
52 
53             var factory = new WindsorServiceHostFactory<Castle.Facilities.WcfIntegration.Rest.RestServiceModel>(IocManager.IocContainer.Kernel);
54         }
55     }
56 }
View Code

并且在.svc中将表签Service中的内容替换为你注入的服务名称,在上面我注入了一个StudentService服务,那么我在Service这边就是填写Service="StudentService"。如果描述不够清楚,我稍后会放出我做的Demo。

同时说明,该Demo为纯手工建立没有在官网下模板制作的。

Github项目地址服务端

配套客户端(WPF)

原文地址:https://www.cnblogs.com/FlyStupidBird/p/8945424.html