Code Monkey home page Code Monkey logo

Comments (10)

fanliang11 avatar fanliang11 commented on August 20, 2024
this.GetService<IUser2Service>().GetUserName(123);

如果是远程调用就引用接口,如果是本地调用就要引用模块的领域服务和接口了。订单服务还需要添加
option.AddRelateService();//添加支持服务代理 ,具体可以看看 #37

from surging.

daofenglg avatar daofenglg commented on August 20, 2024

代码实现:
` 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.

fanliang11 avatar fanliang11 commented on August 20, 2024
this.GetService<IUser2Service>().GetUserName(123);

这个方法就可以了,不需要创建代理,会自动判断是否远程调用

from surging.

daofenglg avatar daofenglg commented on August 20, 2024
  1. var result = this.GetService().GetMembers(10).Result; 是本地的接口是可以调用的
  2. 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.

fanliang11 avatar fanliang11 commented on August 20, 2024

option.AddRelateService();添加了吗

from surging.

daofenglg avatar daofenglg commented on August 20, 2024
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.

fanliang11 avatar fanliang11 commented on August 20, 2024

错误信息贴出来

from surging.

daofenglg avatar daofenglg commented on August 20, 2024

qq 20180105164900

from surging.

fanliang11 avatar fanliang11 commented on August 20, 2024

不支持直接返回string,请用Task

from surging.

daofenglg avatar daofenglg commented on August 20, 2024

刚才那个问题解决了,我接口的返回都改成了task,但是又有一个新的问题

qq 2018010516490011

下面是接口的声明
[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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.