在使用Reflection调用WCF方法时,调用'Exception的目标引发了'异常' [英] Getting 'exception has been thrown by the target of an invocation' Exception while calling a WCF method using Reflection

查看:74
本文介绍了在使用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(), "http://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的目标引发了'异常'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆