Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

服务调用 #24

Closed
hyihao opened this issue Dec 18, 2017 · 18 comments
Closed

服务调用 #24

hyihao opened this issue Dec 18, 2017 · 18 comments

Comments

@hyihao
Copy link

hyihao commented Dec 18, 2017

serviceProxyProvider.Invoke(model, path, serviceKey);
我写了一个测试 在service.client
public static void Test(IServiceProxyProvider serviceProxyProvider)
{
Dictionary<string, object> model = new Dictionary<string, object>();
model.Add("UserId", "1");
string path = "api/user/getuser";
string serviceKey = "User";

        var userProxy = serviceProxyProvider.Invoke<object>(model, path, serviceKey);
        var s = userProxy.Result;
    }

想通过api 方式调用服务
服务端和客户端启动后
image
user返回的信息
image
返回的是自定义属性当中的?
image

@fanliang11
Copy link
Owner

已经注册了,请在网关修改

@hyihao
Copy link
Author

hyihao commented Dec 18, 2017

拉取最新代码?

@fanliang11
Copy link
Owner

 public static void TestForRoutePath(IServiceProxyProvider serviceProxyProvider)
        {
            Dictionary<string, object> model = new Dictionary<string, object>();
            model.Add("user",  new
            {
                Name = "fanly",
                Age = 18,
                UserId = 1
            });
            string path = "api/user/getuser";
            string serviceKey = "User";

            var userProxy = serviceProxyProvider.Invoke<object>(model, path, serviceKey);
            var s = userProxy.Result;
            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
        }

@phil-guo
Copy link
Contributor

phil-guo commented Jan 8, 2018

在客户端调用服务端的时候 发生错误给定的密钥不在字典当中不知是什么意思,服务端提示消息发送失败。 @fanliang11
image

@phil-guo
Copy link
Contributor

phil-guo commented Jan 8, 2018

Dictionary<string, object> model = new Dictionary<string, object>
{
{
"audit", JsonConvert.SerializeObject(new
{
UserName = "simple",
Action = "testaction",
MentodName = "test",
MethodParams = "params",
OperatorIp = "127.0.0.1"
})
}
};

        string path = "api/audit/insertAuditAsync";
        string serviceKey = "Audit";
        var userProxy = serviceProxyProvider.Invoke<object>(model, path, serviceKey); 调用方法是这样

@fanliang11
Copy link
Owner

不需要再JsonConvert.SerializeObject

@fanliang11
Copy link
Owner

serviceProxyProvider.Invoke(model, path, serviceKey);
不推荐使用,因为不支持缓存拦截

@phil-guo
Copy link
Contributor

phil-guo commented Jan 8, 2018

不是这样的,在源码的demo中JsonConvert.SerializeObject 有这个也是可以调用成功,nuget上下载的,有没有JsonConvert.SerializeObject 都会报出这样的错误

@phil-guo
Copy link
Contributor

phil-guo commented Jan 8, 2018

因为不想去引用服务的dll,所以用serviceProxyProvider.Invoke(model, path, serviceKey)这种方式

@fanliang11
Copy link
Owner

贴下你的方法参数

@fanliang11
Copy link
Owner

ModuleName 设置的什么

@phil-guo
Copy link
Contributor

phil-guo commented Jan 8, 2018

image
image
每一个参数都是必须传的吗?

@phil-guo
Copy link
Contributor

phil-guo commented Jan 8, 2018

ModuleName 设置的是Audit

@phil-guo
Copy link
Contributor

phil-guo commented Jan 8, 2018

image
接口的方法是这样定义的

@fanliang11
Copy link
Owner

Dictionary<string, object> model = new Dictionary<string, object>
{
{
"entity", new
{
UserName = "simple",
Action = "testaction",
MentodName = "test",
MethodParams = "params",
OperatorIp = "127.0.0.1"
}
}
};
string path = "api/audit/insertAuditAsync";
string serviceKey = "Audit";
var userProxy = serviceProxyProvider.Invoke(model, path, serviceKey); 

试试

@phil-guo
Copy link
Contributor

phil-guo commented Jan 8, 2018

ok,调用成功,感谢作者。这里实体的时候 字典的键 都必须是entity?

@fanliang11
Copy link
Owner

记得点个赞

@phil-guo
Copy link
Contributor

phil-guo commented Jan 8, 2018

嗯呐,测试完了之后,会写个博客把踩了的坑 都写出来,大家一起学习。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants