公开 WCF 4.0 Rest 模板服务的元数据
可能缺少一些非常基本的东西。我创建了一个 WCF 4.0 Rest 服务。当我从浏览器访问 URL 并且得到我想要的内容时,它没有任何问题。
但现在我想从客户端 mvc 应用程序使用该服务(它也将被其他非 .net 平台使用,这就是为什么它首先是一个休息服务)。
问题是如何获取它的服务引用,以便我可以开始在我的 C# 代码中使用它?使用新的最小 WCF .net 4 配置方法并且没有服务契约的接口,我不知道如何指定 mex 端点。最终我不想在生产中使用 mex 端点,而只是在开发期间使用。我希望能够指定我的所有服务(一个应用程序中大约有 10 个)都具有带有一小段配置的端点,当我发布时,vs2010 .config 转换会将其撕掉。
Probably missing something very basic. I created a WCF 4.0 Rest Service. It works no problems when I'm hitting the url from a browser and I'm getting back what I want.
But now I want to use that service from a client mvc application (it will also be used by other non .net platforms which is why it's a rest service in the first place).
Problem is how do I get a service reference to it so I can start to use it in my c# code? With the new minimal WCF .net 4 config approach and no interface for the service contract, I don't know how to specify a mex endpoint. Ultimately I don't want a mex endpoint in production, just during development. I would love to be able to specify that all my services (around 10 in one application) have endpoints with one tiny piece of config that vs2010 .config transformations just rips out when I publish.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
停止。 REST 服务不使用元数据。元数据(Mex 端点)仅适用于 SOAP 服务,因为 WSDL 1.1(唯一支持的版本< /a> by WCF) 只能描述 SOAP 服务。 WADL 或 WSDL 2.0 能够描述 REST 服务,但目前 WCF 都不支持它们。
REST 服务可以通过直接使用
WebRequest
或在共享合约之上构建ChannelFactory
来使用。这两种方法都有描述 这里。另一种方法是使用 REST Starter kit 中的HttpClient
(以前应用程序编程接口)。 Starter 工具包的问题是它从未达到 RTM(已被 WCF 4 取代)。 WCF 4 REST 服务提供的不是元数据端点 帮助页面,其中描述了所有操作。使用 WCF 4 REST 模板时,帮助页面应该已打开 - 只需将 /help 后缀添加到您的服务地址即可。 这是另一篇关于构建 REST 客户端的文章。Stop. REST service doesn't use metadata. Metadata (Mex endpoint) are only for SOAP services because WSDL 1.1 (the only version supported by WCF) is able to describe only SOAP service. WADL or WSDL 2.0 is able to describe REST service but non of them is currently supported by WCF.
REST service is consumed by using
WebRequest
directly or by buildingChannelFactory
on top of shared contracts. Both methods are described here. Other method is to useHttpClient
from REST Starter kit (former API). The problem with Starter kit is that it has never reached RTM (it was replaced by WCF 4). Instead of metadata endpoint WCF 4 REST service offers help page where all operation are described. When using WCF 4 REST template the help page should be already turned on - just add /help sufix to address of your service. Here is another article about building REST clients.