开发者

Creating a WCF service using http

I'm trying to simulate an existing API and I would love to get some help.

How can I create a WCF service that will respond t开发者_StackOverflowo:

http://www.something.com/dothis?param1=x&param2=y

And will run the function dothis with the given parameters' values. And then it needs to return an XML response.

I looked it up but I would love to get some directions, links or better search terms.

Thanks!


You might want to start here for nice REST WCF services.

The main thing you need to know is about the interface:

[ServiceContract]
public interface IMSDNMagazineService
{
    [OperationContract]
    [WebGet(UriTemplate="/")]
    IssuesCollection GetAllIssues();
    [OperationContract]
    [WebGet(UriTemplate = "/{year}")]
    IssuesData GetIssuesByYear(string year);
    [OperationContract]
    [WebGet(UriTemplate = "/{year}/{issue}")]
    Articles GetIssue(string year, string issue);
    [OperationContract]
    [WebGet(UriTemplate = "/{year}/{issue}/{article}")]
    Article GetArticle(string year, string issue, string article);
    [OperationContract]
    [WebInvoke(UriTemplate = "/{year}/{issue}",Method="POST")]
    Article AddArticle(string year, string issue, Article article);

}

The WebInvoke attribute will get you what you want while using a nice url. So you would end up with something like http://www.something.com/dothis/x/y.


You might want to take a look at UriTemplate.

http://msdn.microsoft.com/en-us/library/bb675245.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜