我想了解WCF,所以我的问题可能是愚蠢的。我相信我有GET操作的坚定的认识。我现在工作的一些POST操作。我的问题是,我可以写一个WCF服务操作,具有WebInvoke,接受多个参数?或者,当我发布的数据,将其只接受一个序列化的参数?
I'm trying to understand WCF, so my questions may be dumb. I believe I have a firm understanding of "GET" operations. I'm now working on some "POST" operations. My question is, can I write a WCF Service operation, with WebInvoke, that accepts multiple parameters? Or, when I POST data, will it only accept a single serialized parameter?
感谢您!
推荐答案是的,但你的POST将有在使用数据的共同理解,又名数据契约获得通过。
Yes, but your POST will have to be passed in using a common understanding of the data, aka a "data contract".
在WCF,这里典型的做法是,你需要创建一个类合同(只是一个离我的头例子,不是100%的工作))
In WCF, the typical approach here is that you'd create a contract class (just an off-my-head example, not 100% working))
[DataContract(Namespace="yournamespace")] public class MyContract { [DataMember(Order=1)] public string MyData1 { get(); set{};} [DataMember(order=2)] public string MyData2 { get(); set{};} }
然后你指定你的WCF操作接受合同类型作为参数
Then you'd specify your WCF operation to accept that contract type as its parameter
[WebInvoke(method="POST")] public string DoSomethingFromPost(MyContract postedData) { }在你的客户,你会数据序列化到XML / JSON是你的合同相符。此外,宽松的例子:
On your client, you'd serialize the data to an xml/json that matches your contract. Again, loose example:
<MyContract xmlns="yournamespace"> <MyData1>value</MyData1> <MyData2>value</MyData2> </MyContract>在合同相匹配,WCF将deserialze您的文章到你的合同的对象,在这一点你可以使用它像任何其他类。
When the contract matches, WCF will deserialze your POST into your contract object, at which point you can use it like any other class.
更多推荐
POST多个参数WCF服务
发布评论