1

我是 wcf 服务开发的新手。我有以下问题:我正在使用这样的 URI 模板创建 wcf-service:

[OperationContract, WebGet(UriTemplate = "/EmpDetails/command/?command=SaveDetails&id={id}&data{empid:{EmpID},EmpName:{EmpName},EmpAge:{EmpAge}}"

如何访问这些值以保存详细信息?

另一件事是我希望此 URL 用于保存详细信息。

http://12.154.21.23:8888/EmpDetails/command/?command=SaveDetails&data={empid:Test,EmpName:TestName,EmpAge:26}
4

1 回答 1

3

You need to create a class somewhere in service:

[DataContract]
public class Data
{
    [DataMember]
    public int EmpID {get;set;}
    [DataMember]
    public string EmpName{get;set;}
    [DataMember]
    public string EmpAge {get;set;}
}

Next, add this to your wcf service interface:

[OperationContract]
[WebGet(UriTemplate = "/EmpDetails/command/?command=SaveDetails&id={id}&data{EmpID:{EmpID},EmpName:{EmpName},EmpAge:{EmpAge}}")]
void SaveDetails(int id, Data data);

and finally, add code below to class implementing wcf service interface:

public void SaveDetails(int id, Data data)
{
    //do smt
}
于 2013-05-18T07:19:03.027 回答