我可以使用 UriTemplate 将非字符串传递给 WCF RESTful 服务吗? [英] Can I pass non-string to WCF RESTful service using UriTemplate?

查看:28
本文介绍了我可以使用 UriTemplate 将非字符串传递给 WCF RESTful 服务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以执行以下操作吗?

Can I do the following?

[OperationContract]
[WebGet(UriTemplate = "/foo/{id}")]
string GetFoo(int id);

我希望我的服务既作为 RESTful 服务又作为 RPC 风格的 SOAP 服务.如果可能,我想将 int 保留为 int,而不是手动解析.

I'd like my service to function as both RESTful service and RPC-style SOAP service. If possible I'd like to retain int as int, and not do parsing by hand.

推荐答案

如果我没记错的话,在使用 WebGet 或 WebInvoke 时,路径中的 UriTemplate 变量总是解析为字符串.只有在 UriTemplate 的查询部分中,您才能将 UriTemplate 变量绑定到 int、long 等.

If I remember correctly, UriTemplate variables in the path always resolve to strings when using WebGet or WebInvoke. You can only bind UriTemplate variables to int, long, etc. when they are in the query portion of the UriTemplate.

这篇关于我可以使用 UriTemplate 将非字符串传递给 WCF RESTful 服务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆