Error calling a service through Serviceclient in C#

Asked

Viewed 37 times

0

I have a part in the project (MVC that connects to BD through web services) of my company that calls WCF services this way:

public static ReturnType CallWebMethod<TService, ReturnType>(String endpointConfigurationName, String myMethod, object[] parameters = null)
    where TService : class
    {
        var client = new ServiceClient<TService>(endpointConfigurationName);

        // Get a type from the class 
        Type type = client.Proxy.GetType();

        // Retrieve the method you are looking for
        MethodInfo methodInfo = type.GetMethod(myMethod);

        ReturnType result;
        bool success = false;
        try
        {
            // Invoke the method on the instance we created above
            result = (ReturnType)methodInfo.Invoke(client.Proxy, parameters);
            if (client.State != CommunicationState.Faulted)
            {
                client.Close();
                success = true;
            }
        }
        finally
        {
            if (!success)
                client.Abort();
        }

        return result;
    }

I downloaded the project from the repository (the project in the repository is the final version that is in production) and have received the error Object Reference not set to an instance of an object because of the methodInfo, which is null. I supposedly send the service name and the method name, both valid (work in production), but he can’t find them.

I make the call like this:

return ServicesHelper.CallWebMethod<BusinessServicesImplementation.IBusinessOportunitiesService, bool>
             ("BusinessServicesImplementation.BusinessOportunitiesService", "SyncUpGpc_Aiccopn_Users_and_Companies", par);

What can I do to try to identify the problem?

  • What are you calling it?

  • I’ve already edited and added the call, the variable par is irrelevant, but it is an array of objects

  • The problem is in SyncUpGpc_Aiccopn_Users_and_Companies. I know it’s not your fault, but this is a huge scam, I wouldn’t even use this code.

  • This class is to call any service that is in your WCF Tract ???

  • what’s wrong with that code?

  • @Juliosoares yes, basically pass the name of the service and then the method, but when it does not find!

  • Honestly @ihavenokia, I prefer to work with clients directly in my application and independent... I find this use of Reflection somewhat unnecessary since calling my services directly I already have the definitions and types that will be returned... there is unnecessary processing in this class

  • I’m going to transform the method so that it directly calls the web service, instead of building it, that, in principle, will solve my problem

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.