0

I am trying to dynamically create a proxy using the WSDL of a WCF web service and call a method on it. The method signature in the WCF service I am trying to call by constructing a proxy at runtime is as follows:

(I am using the DynamicProxy code from MSDN for this purpose which is located here)

I create a proxy using the wsdl at runtime using the following code snippet -

    var factory = new DynamicProxyFactory(wsdl);
    var proxy = factory.CreateProxy(contract);
    object value1 = topic;
    object value2 = emailMessage;
    object value3 = messageProperties; //This is of type List<KeyValuepair<string,string>>

     proxy.CallMethod(method, value1, value2, value3);

The method in the above call has the signature that is listed below:

    void ReceiveMessage(string topic, string message, List<KeyValuePair<string, string>> propertyBag);

Once I dynamically create a proxy for the web service containing the above method, and do a type.InvokeMember on it, I get a method not found exception.

However, when I try to invoke a similar method with all strings as arguments, I can invoke the method successfully. For example, the following method gets invoked successfully

    void ReceiveMessage2(string message, string topic, string anything);

The way I am using the InvokeMember is pretty straightforward

    public object CallMethod(string method, params object[] parameters)
    {
        object retval = this.objType.InvokeMember(
            method,
            BindingFlags.InvokeMethod | CommonBindingFlags,
            null /* Binder */,
            this.obj,
            parameters /* args */);

        return retval;
    }

Can someone please help me in figuring out what I am doing wrong? I am passing the objects the same way for both the calls (ReceiveMessage and ReceiveMessage2). Thanks in advance. This has been driving me nuts.

EDIT:

The commonBindingFlags in the above function is actually is a wrapper for this -

     BindingFlags.Instance | BindingFlags.Public;
ravij
  • 1
  • 3

1 Answers1

0

I found a solution to my problem. Looks like the KeyValuePair is not serializable. I used

    Dictionary<string, string> 

instead of

    List<KeyValuePair<string,string>> 

and it solved the problem.

Thanks

ravij
  • 1
  • 3