asmx Web 服务和键值参数
我目前有一个像这样定义的 asmx 方法:
[WebMethod]
public String Method1(Hashtable form)
它接收具有可变数量属性的 json 对象,例如:
{"form":{"name1":"10","name2":"20"}}
这工作正常并在调用时给出预期结果,但是当我在浏览器中打开 Web 服务地址时,我得到错误:
不支持 System.Collections.Hashtable 类型,因为它实现了 IDictionary
我尝试过其他数据类型,例如 List
它将修复此问题,但在调用方法时为空,并且我找不到在这两种情况下都有效的东西......
这样做的“正确”方法是什么?
I currently have an asmx method defined like so :
[WebMethod]
public String Method1(Hashtable form)
It receives json objects with a variable number of attributes, for example :
{"form":{"name1":"10","name2":"20"}}
This is working fine and gives the expected results when called, but when I open the web service address in the browser, I get the error :
The type System.Collections.Hashtable is not supported because it implements IDictionary
I've tried other data types, like List<DictionaryEntry>
which will fix this, but then be empty when the method is called, and I can't find something that will work in both cases...
What is the "correct" way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IDictionary
无法序列化为 XML(这就是 asmx Web 服务的工作方式),因此您不能使用IDictionary
的任何实现作为返回值或参数。因此,“正确”的方法是使用任何未实现 IDictionary 的方法。你可以这样做:
然后像这样调用它:
IDictionary
cannot be serialized to XML (which is how asmx web services work), so you cannot use any implementation ofIDictionary
either as a return value or as a parameter.So the "correct" way of doing this is to use anything that doesn't implement
IDictionary
. You could do something like this instead:and then call it like this:
目前,我可以将其作为解决方法:
并且服务 .asmx 页面加载时不会出现错误。
但这对我来说仍然没有意义......
For the time being, I can do this as a workaround :
And the service .asmx page loads without error.
This still makes no sense to me though...