Comments (10)
this.GetService<IUser2Service>().GetUserName(123);
如果是远程调用就引用接口,如果是本地调用就要引用模块的领域服务和接口了。订单服务还需要添加
option.AddRelateService();//添加支持服务代理 ,具体可以看看 #37
from surging.
代码实现:
` var serviceProxyFactory=this.GetService();
var userProxy = serviceProxyFactory.CreateProxy<IFactService>();
Task task= userProxy.GetFacts(10);
`
接口已经引用到项目,在调用时引发了异常:
System.InvalidCastException:“Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.QualifiedNameSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.GenericNameSyntax'.”
from surging.
this.GetService<IUser2Service>().GetUserName(123);
这个方法就可以了,不需要创建代理,会自动判断是否远程调用
from surging.
- var result = this.GetService().GetMembers(10).Result; 是本地的接口是可以调用的
- this.GetService().GetFacts(10);这个是需要远程调用的接口,还是报上面那个异常。
以下是远程调用接口的实现:
[ServiceBundle("api/{Service}")]
public interface IFactService:IServiceKey
{
[Command(ExecutionTimeoutInMilliseconds = 1000*5, RequestCacheEnabled = false)]
[Service(Date = "201-01-03", Director = "ligang", Name = "获取品牌数据")]
Task GetFacts(int count);
[Service(Date = "2018-01-03", Director = "ligang", Name = "测试方法")]
string GetTst();
}
from surging.
option.AddRelateService();添加了吗
from surging.
class Program
{
static void Main(string[] args)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var host = new ServiceHostBuilder()
.RegisterServices(builder =>
{
builder.AddMicroService(option =>
{
option.AddServiceRuntime();
option.AddRelateService(); ;//添加支持服务代理
//option.UseZooKeeperManager(new ConfigInfo("127.0.0.1:2181"));
option.UseConsulManager(new ConfigInfo("192.168.1.199:8500"));
option.UseDotNettyTransport();
option.UseRabbitMQTransport();
option.AddRabbitMQAdapt();
//option.UseProtoBufferCodec();
option.UseMessagePackCodec();
builder.Register(p => new CPlatformContainer(ServiceLocator.Current));
});
})
.SubscribeAt()
.UseLog4net("Configs/log4net.config")
//.UseServer("127.0.0.1", 98)
//.UseServer("127.0.0.1", 98,“true”) //自动生成Token
//.UseServer("127.0.0.1", 98,“123456789”) //固定密码Token
.UseServer(options =>
{
options.Ip = "127.0.0.1";
options.Port = 11011;
options.Token = "True";
options.ExecutionTimeoutInMilliseconds = 30000;
options.MaxConcurrentRequests = 200;
})
.UseStartup<Startup>()
.Build();
using (host.Run())
{
Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
}
}
}
from surging.
错误信息贴出来
from surging.
from surging.
不支持直接返回string,请用Task
from surging.
刚才那个问题解决了,我接口的返回都改成了task,但是又有一个新的问题
下面是接口的声明
[ServiceBundle("api/{Service}")]
public interface IFactService:IServiceKey
{
[Command(ExecutionTimeoutInMilliseconds = 1000 * 5, RequestCacheEnabled = false)]
[Service(Date = "201-01-03", Director = "ligang", Name = "获取品牌数据")]
Task<List> GetFacts(int count);
//[Service(Date = "2018-01-03", Director = "ligang", Name = "测试方法")]
//Task<List<string>> GetTst();
}
下面是通过引用查看看到的临时文件内容
[global::Surging.Core.CPlatform.Runtime.Server.Implementation.ServiceDiscovery.Attributes.ServiceBundleAttribute("api/{Service}")]
public interface IFactService : global::Surging.Core.CPlatform.Ioc.IServiceKey
{
[global::Surging.Core.CPlatform.Support.Attributes.CommandAttribute(ExecutionTimeoutInMilliseconds = 5000, RequestCacheEnabled = false)]
[global::Surging.Core.CPlatform.Runtime.Server.Implementation.ServiceDiscovery.Attributes.ServiceAttribute(Date = "201-01-03", Director = "ligang", Name = "获取品牌数据")]
System.Threading.Tasks.Task<System.Collections.Generic.List<Api.Models.TblFactoryModel>> GetFacts(int count);
}
from surging.
Related Issues (20)
- 两个不同的Modules项目中如何相互调用 HOT 1
- hh
- 单服务热加载问题 HOT 3
- 用jmeter对sayhello做压力测试时,返回结果不一致,entity为1 HOT 1
- k8s
- k8s中单服务重发之后 提示如下 HOT 3
- The community version is the last version. HOT 3
- new feature Protokollwandler component will be updated in SurgingVista version
- 统计一下有多少人使用社区版 HOT 1
- Hot deployment modules and components
- 请问Surging 中使用的 WebSocketCore 的源码是这个地址吗 HOT 1
- server进程占用的内存一直增长,直到进程崩溃,是什么原因? HOT 11
- NLog HOT 6
- surgingSettings.json配置中的Consul 连接ConnectionString配置 HOT 1
- Surging.Core.KestrelHttpServer HOT 1
- 请求参数
- 开源**NCC介绍 HOT 4
- 使用serviceProxyProvider.Invoke调用接口内存持续增长 HOT 4
- TCP network components that support configuring properties
- 服务间通讯导致内存持续增加 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from surging.