This project is read-only.

Method with multiple Complex type parameters

Topics: Web Api
Dec 14, 2011 at 10:34 PM

Is it possible to define a method with multiple complex parameters, as shown in the following sample ?

The idea is to implement an Operation Handler that will produce these parameters (from header, content, etc.). I tried and implemented a handler which produces both c1 and c2. If I left only a single complex-type parameter in the method (either c1 or c2), everything worked fine. When trying the method with both parameters, an exception was raised as follows:

"System.InvalidOperationException: The HttpOperationHandlerFactory is unable to determine the input parameter that should be associated with the request message content for service operation 'Dosomething'. If the operation does not expect content in the request message use the HTTP GET method with the operation. Otherwise, ensure that one input parameter either has it's IsContentParameter property set to 'True' or is a type that is assignable to one of the following: HttpContent, ObjectContent`1, HttpRequestMessage or HttpRequestMessage`1."


using System.ServiceModel;

namespace ContactManager.APIs
    public class ContactsApi

[WebInvoke(UriTemplate = "")]
public int Dosomething(Contact1 c1, Contact2 c2)
    // do something
    return 7;

namespace ContactManager.Resources
public class Contact2 { public int ContactId { get; set; } public string Name { get; set; } }
    public class Contact1
       public int ContactId { get; set; }
       public string Name { get; set; }

Jan 20, 2012 at 1:42 AM

From my experience: No.
It seems that WebApi follows a 1 for 1 model, like fubu and mvc suggest.
That means for every one input, you have one input model designating what it is. 

Jan 20, 2012 at 2:09 AM

This (having multiple complex parameters) will in fact become possible in an upcoming release of WebApi.

Jan 20, 2012 at 2:21 AM

Hi yehuda_a, can you show the code for your handler?

Jan 21, 2012 at 11:28 AM

Unfortunately, the code was left on my old PC. However, it was a very simple Operation handler. It was something like:

public class MultiTypeMappingHandler : HttpOperationHandler

	protected override object[] OnHandle(object[] input)

		return new object[] {
		   new Contact1 {ContactId = 1, Name = "Phil Haack"},
                   new Contact {ContactId = 2, Name = "HongMei Ge"}


Jan 27, 2012 at 7:52 PM

This issue seems to have been resolved in version 6.0 (beta)