在使用Reflection调用WCF方法时,调用'Exception的目标引发了'异常'

编程入门 行业动态 更新时间:2024-10-26 10:31:44
本文介绍了在使用Reflection调用WCF方法时,调用'Exception的目标引发了'异常'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用反射在客户端调用wcf服务方法时调用目标引发了异常。 我在调用该行的方法时遇到异常: object result = oMeth.Invoke(oProxy,@ params); 这是我的服务:

Hi, I'm getting "exception has been thrown by the target of an invocation" while calling a wcf service method at the client side using reflection. I'm getting the exception while invoking the method at the line: object result = oMeth.Invoke(oProxy,@params); Here is my service :

public string GetData(int value) { return string.Format("You entered: {0}", value); }

我的客户端代码:

my client side code:

ChannelFactory<WcfService1.IService1> myFactory = default(ChannelFactory<WcfService1.IService1>); myFactory = new ChannelFactory<WcfService1.IService1>(new BasicHttpBinding(), "localhost:3250"); object oProxy = myFactory.CreateChannel(); Type oType = oProxy.GetType(); MethodInfo oMeth = oType.GetMethod("GetData"); object[] @params = { 3 }; object result = oMeth.Invoke(oProxy,@params);

Plz帮助,如果知道解决方案。 谢谢&问候, Ramana

Plz help if know the solution. Thanks & Regards, Ramana

推荐答案

看看 this [ ^ ]并检查它是否适用于您。 Take a look at this[^] and check if it will work on your side.

当抛出异常时,深入了解innerexception详细信息 - 那里有更多信息! 你的服务端点没有使用BasicHttpBinding或你的网址错误。我怀疑是后者。 你的代码对我来说很好。 When the exception gets thrown, drill down into the innerexception details - there's more info there! Either your service endpoint isn't using a BasicHttpBinding or your URL is wrong. I suspect the latter. Your code works fine for me.

在我的情况下也会发生同样的错误。我发现当我传递错误的参数名称时,会发生错误。否则它工作正常 In my case also same error occur.i found that when i'm passing wrong parameter name then error occur. otherwise it is working fine

更多推荐

在使用Reflection调用WCF方法时,调用'Exception的目标引发了'异常'

本文发布于:2023-11-04 17:35:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1558575.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:引发了   异常   目标   方法   Reflection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!