使用DataContract对象调用RESTful WCF操作

时间:2013-01-13 00:50:09

标签: wcf datacontract

我的ServiceContract中有以下OperationContract:

[WebInvoke(Method="POST", UriTemplate="books")]
[OperationContract]
void AddBookToInventory(BookTitle aBook);

BookTitle是一个DataContract对象:

[DataContract(Namespace="http://someurl.com/books")]
public class BookTitle
{
    string title = "";
    string author = "";
    string isbn = "";
    decimal price = 0.00m;


    [DataMember]
    public string Title
    {
        get { return title; }
        set { title = value; }
    }

    [DataMember]
    public string Author
    {
        get { return author; }
        set { author = value; }
    }

    [DataMember]
    public string Isbn
    {
        get { return isbn; }
        set { isbn = value; }
    }

    [DataMember]
    public decimal Price
    {
        get { return price; }
        set { price = value; }
    }

}

如何在c#或vb中使用来自.NET客户端的XML调用AddBookToInventory操作?

1 个答案:

答案 0 :(得分:0)

您必须将POST webrequest写入网址http://yourServiceName.svc/books