简体   繁体   中英

How to use OUT parameter values returned from METHOD.INVOKE in C#

I am using C# 2.0,

I am trying to call webmethod of my webservice, please see below code sample:

    try
    {

        Type objtype = Type.GetType(crisresult.ToString());
        object obj = Activator.CreateInstance(objtype);

        Object[] mArgs = new Object[methodArgs.Length + 1];
        methodArgs.CopyTo(mArgs, 0);
        mArgs.SetValue(obj, methodArgs.Length);
        methodArgs = mArgs;

        Object result = mi.Invoke(service, methodArgs);

        JObject parsed = JObject.Parse(result.ToString());

        // option 1) if you are just using primitives
        foreach ( KeyValuePair<string, JToken> pair in parsed)
        {
            Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
        }      
    }

Now in above code in my methodArgs object array is having an out parameter(crisresult), now incase of any error returned from my webservice method Object result = mi.Invoke(service, methodArgs); is shown in my out parameter, I am sure that my out parameter is the last object in my methodArgs object array, I am looking to get that object and check for the error result returned from the webservice.

Please suggest!

Your methodArgs will have been updated to account for any ref / out parameters. Since you believe it is the last one:

object foo = methodArgs[methodArgs.Length-1];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM