WCF和HTTP GET [英] WCF and HTTP GET

查看:84
本文介绍了WCF和HTTP GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WCF服务公开此功能

My WCF service exposes this function

public SerialNumberInfo GetSerialNumberInfo(string serialNumber) { }

有没有办法在我的WCF服务上启用HTTP GET?示例:

Is there a way to enable HTTP GET on my WCF service? Example:

http://localhost:8004/MyService/GetSerialNumberInfo?serialNumber=4


推荐答案

是的,你需要使用 webHttpBinding 在您的WCF服务上。

yes, you need to use the webHttpBinding on your WCF service.

有关WCF中REST支持的更多信息,请参阅WCF REST入门工具包。

See the WCF REST Starter Kit for more information on REST Support in WCF.

  • REST in WCF
  • Overview of REST in WCF
  • Series of screencasts on how to use REST in WCF

如果您在IIS中托管服务,则需要创建单独的* .svc文件REST服务(让我们称之为 RESTService.svc ),其中包含:

If you're hosting your service in IIS, you need to create a separate *.svc file for the REST service (let's call it RESTService.svc), which contains:

<%@ ServiceHost Service="YourServiceName" Language="C#" debug="False"
    Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

现在你应该可以连接到URL

Now you should be able to connect to the URL

http://localhost:8004/MyService/RESTService.svc

并以REST形式获取您的数据。

and get your data RESTfully.

Marc

这篇关于WCF和HTTP GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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