公开 WCF 4.0 Rest 模板服务的元数据 [英] Exposing meta data for a WCF 4.0 Rest Template Service

查看:28
本文介绍了公开 WCF 4.0 Rest 模板服务的元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能缺少一些非常基本的东西.我创建了一个 WCF 4.0 休息服务.当我从浏览器点击 url 并且我得到我想要的东西时,它没有问题.

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.

但现在我想从客户端 mvc 应用程序中使用该服务(它也将被其他非 .net 平台使用,这就是为什么它首先是一个休息服务).

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).

问题是我如何获得对它的服务引用,以便我可以开始在我的 c# 代码中使用它?使用新的最小 WCF .net 4 配置方法并且没有服务合同的接口,我不知道如何指定 mex 端点.最终,我不希望在生产中使用 mex 端点,只是在开发过程中.我希望能够指定我的所有服务(在一个应用程序中大约有 10 个)都具有带有一小块配置的端点,vs2010 .config 转换在我发布时就会被撕掉.

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.

推荐答案

停止.REST 服务不使用元数据.元数据(Mex 端点)仅用于 SOAP 服务,因为 WSDL 1.1(唯一支持的版本 by WCF) 只能描述 SOAP 服务.WADL 或 WSDL 2.0 能够描述 REST 服务,但 WCF 目前不支持它们.

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 服务通过直接使用 WebRequest 或通过在共享合约之上构建 ChannelFactory 来使用.两种方法都有描述 此处.其他方法是使用 REST Starter kit(前API).Starter kit 的问题在于它从未达到 RTM(它被 WCF 4 取代).而不是元数据端点 WCF 4 REST 服务提供 帮助页面,其中描述了所有操作.使用 WCF 4 REST 模板时,帮助页面应该已经打开 - 只需将/help 后缀添加到您的服务地址.这是另一篇关于构建 REST 客户端的文章.

REST service is consumed by using WebRequest directly or by building ChannelFactory on top of shared contracts. Both methods are described here. Other method is to use HttpClient 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.

这篇关于公开 WCF 4.0 Rest 模板服务的元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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