WCF and HTTP GET

2019-06-26 12:58发布

My WCF service exposes this function

public SerialNumberInfo GetSerialNumberInfo(string serialNumber) { }

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

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

标签: wcf http
2条回答
Emotional °昔
2楼-- · 2019-06-26 13:32

What you want to do sounds like building a RESTful service with WCF. Check out the following article on MSDN, it has all the details:

A Guide to Designing and Building RESTful Web Services with WCF 3.5

查看更多
干净又极端
3楼-- · 2019-06-26 13:45

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

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

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" %>

Now you should be able to connect to the URL

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

and get your data RESTfully.

Marc

查看更多
登录 后发表回答