命名服务
Posted 百小僧
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了命名服务相关的知识,希望对你有一定的参考价值。
命名服务
using System; namespace Microsoft.Extensions.DependencyInjection public static class NamedServiceExtensions private delegate TService Resolver<out TService>(IServiceProvider serviceProvider, string serviceName); public static TService GetNamedService<TService>( this IServiceProvider provider, string serviceName) return ((Resolver<TService>)provider .GetService(typeof(Resolver<TService>))) ?.Invoke(provider, serviceName); public static IServiceCollection AddNamedTransient<TService, TImplementation>( this IServiceCollection services, string name) where TService : class where TImplementation : class, TService services.AddTransient<TService, TImplementation>(); services.AddTransient(provider => (Resolver<TService>)((sp, sn) => sn == name ? sp.GetService<TService>() : null)); return services; public static IServiceCollection AddNamedScoped<TService, TImplementation>( this IServiceCollection services, string name) where TService : class where TImplementation : class, TService services.AddScoped<TService, TImplementation>(); services.AddTransient(provider => (Resolver<TService>)((sp, sn) => sn == name ? sp.GetService<TService>() : null)); return services; public static IServiceCollection AddNamedSingleton<TService, TImplementation>( this IServiceCollection services, string name) where TService : class where TImplementation : class, TService services.AddSingleton<TService, TImplementation>(); services.AddTransient(provider => (Resolver<TService>)((sp, sn) => sn == name ? sp.GetService<TService>() : null)); return services; var services = new ServiceCollection(); services.AddNamedTransient<IMyService, MyService>("serviceA"); services.AddNamedScoped<IMyService, MyOtherService>("serviceB"); services.AddNamedSingleton<IMyService, MyThirdService>("serviceC"); var serviceProvider = services.BuildServiceProvider(); var serviceA = serviceProvider.GetNamedService<IMyService>("serviceA"); var serviceB = serviceProvider.GetNamedService<IMyService>("serviceB"); var serviceC = serviceProvider.GetNamedService<IMyService>("serviceC");
Corba 命名服务
【中文标题】Corba 命名服务【英文标题】:Corba naming service 【发布时间】:2011-12-19 18:15:33 【问题描述】:我需要一些帮助...
我必须将 ma Corba 服务器与一个 Java Web 服务通信... 所以我必须确定命名服务.. 对吗??
我杀死了端口 2809 中的 omniNames 并运行代码: tnameserv -ORBport 2809
给我
初始命名上下文: IOR:000000000000002b49444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f6e746578744578743a312e300000000000010000000000000096000102000000000a3132372e302e312e3100038400000045afabcb0000000020000f424000000001000000000000000200000008526f6f74504f41000000000d544e616d65536572766963650000000000000008000000010000000114000000000000020000000100000020000000000001000100000002050100010001002000010109000000010001010000000026000000020002 TransientNameServer:将初始对象引用的端口设置为:900 准备好了。
在我运行 server.py 并返回异常之后:
文件“server.py”,第 28 行,在 obj = orb.resolve_initial_references("NameService") 文件“/usr/lib/python2.7/dist-packages/omniORB/CORBA.py”,第 576 行,在 resolve_initial_references return _omnipy.orb_func.resolve_initial_references(self, identifier) omniORB.CORBA.NO_RESOURCES: CORBA.NO_RESOURCES(omniORB.NO_RESOURCES_InitialRefNotFound, CORBA.COMPLETED_NO)
我要做什么?
【问题讨论】:
【参考方案1】:我不是 Java 名称服务专家,但 Corba 规范的默认 orb 是 2809。 虽然 java 默认值为 900。您的名称服务从 900 开始,就像它告诉您的那样,但 omniorb 会在 2809 处查找它。
Web 说 tnameserv 的语法是:
tnameserv -ORBInitialPort 2809
【讨论】:
【参考方案2】:首先在您的终端上运行此命令。 (请确保您已经安装了 JDK):
orbd -ORBInitialiPort 2809.
之后你必须运行服务器然后运行客户端。
【讨论】:
以上是关于命名服务的主要内容,如果未能解决你的问题,请参考以下文章