2012-03-25 100 views
2

有没有一种方法可以使用GET将值数组传递给WCF WEB API服务?我想提出以下调用我的服务:如何将Uri中的数组传递给WCF WEB API服务?

http://localhost/myservice.com/projects/workspaceUsers?token=A3AD62998A7A463A9AD23D8F2937C92220120325072846&workspaceId=208&workspaceId=209 

我的Web服务功能是这样的:

[WebGet(UriTemplate = "workspaceUsers?token={token}&workspaceId={workspaceId}")] 
    public HttpResponseMessage<IEnumerable<WorkspaceUserReadOnlyChildData>> FetchWorkspaceUserList(string token, int workspaceId) 

的想法是只是改变INT workspaceId为int [] workspaceId,但导致以下错误:

The service operation 'FetchWorkspaceUserList' will never receive a value for the input parameter 'workspaceId' of type 'Int32[]'. Ensure that a request HttpOperationHandler has an output parameter with a type assignable to 'Int32[]'. 

有没有办法做到这一点,而不需要像使用POST传递条件对象?

感谢您的帮助!

+0

为什么不尝试逗号分隔值,而不是int数组。如果你使用ASP.Net MVC或新的Web API,你可以使用ModelBinders – Chandermani 2012-03-26 05:50:34

回答

1

我认为最简单的事情就是更新到ASP.NET 4 WEB API。由于它采用标准控制器架构,因此您可以轻松传入数组。

+0

我发现这也是最好的解决方案。 – mattruma 2012-03-26 13:39:25