POST多个参数WCF服务

编程入门 行业动态 更新时间:2024-10-28 06:31:09
本文介绍了POST多个参数WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想了解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服务

本文发布于:2023-10-11 04:46:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1480723.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   参数   POST   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!