【问题标题】:Creating a WCF service using http使用 http 创建 WCF 服务
【发布时间】:2011-06-23 17:32:46
【问题描述】:

我正在尝试模拟现有的 API,我很想得到一些帮助。

如何创建一个 WCF 服务来响应:
http://www.something.com/dothis?param1=x&param2=y

并将使用给定参数的值运行函数dothis。然后它需要返回一个 XML 响应。

我查了一下,但我很想得到一些方向、链接或更好的搜索词。

谢谢!

【问题讨论】:

    标签: c# wcf c#-4.0


    【解决方案1】:

    您可能想要启动 here 以获得良好的 REST WCF 服务。

    你需要了解的主要是关于界面的事情:

    [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);
    
    }
    

    WebInvoke 属性将在使用漂亮的 url 时为您提供所需的内容。所以你最终会得到类似http://www.something.com/dothis/x/y的东西。

    【讨论】:

    • 感谢您的详细解答!
    【解决方案2】:

    您可能想看看 UriTemplate。

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

    【讨论】:

      猜你喜欢
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-01
      • 2011-12-21
      相关资源
      最近更新 更多