2

私の最初の WCF Rest サービスを書いていて、うまくいっています...しかし、小さな問題があります。誰か助けてもらえますか?

ローカルPCのヘルプページに移動すると、

  http://localhost/WcfRestService1/help

次のように表示されますが、URI が間違っています。URI が空白であるか、パラメーター {id} のみを要求していることに注意してください。

Uri     Method      Description
            GET     Service at http://localhost/WcfRestService1/
            POST    Service at http://localhost/WcfRestService1/
{id}        GET     Service at http://localhost/WcfRestService1/{ID}
            PUT     Service at http://localhost/WcfRestService1/{ID}
            DELETE  Service at http://localhost/WcfRestService1/{ID}

それは本当にあるべきです(私の方法については以下を参照してください)

  Uri

  Tasks  Get .... 
  Users/{id}    Get ....

ここに私のメソッドがあるので、URI は正しい URI を表示する必要があります。私の属性 UriTemplate を参照してください。

    [WebGet(UriTemplate = "Tasks")]
    public List<SampleItem> GetCollection()
    {
        // TODO: Replace the current implementation to return a collection of SampleItem instances
        return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
    }

    [WebGet(UriTemplate = "Users/{id}")]
    public SampleItem Get(string id)
    {
        // TODO: Return the instance of SampleItem with the given id
        //throw new NotImplementedException();
        return new SampleItem() {Id = 1, StringValue = "Hello"};
    }
4

0 に答える 0