如何将名称/值对传递给 ASMX Web 方法?
我正在创建一个 Web 服务,它本质上是远程某些数据库调用(以便它们通过 HTTP 而不是默认的 SQL Server 端口 1433 进行)。
本质上,我一直在尝试做的是将许多参数传递给 ASMX WebService 上的 WebMethod。参数为:
- 代表 ID 的字符串 要执行的查询。
- 数据表 代表结构 该信息应为表 填入.
- 一本字典 参数(即名称值对) 使用以下表示的查询运行 上面的ID得到预期的 结果。
- 一个布尔值是 对这个问题不重要
现在我遇到的问题是 ID 的字符串、DataTable 和布尔值都很好地通过,但字典却没有。我知道默认情况下,XMLSerializing 不支持任何实现 IDictionary 的内容,因此我已将字典转换为两个对象数组,一个用于键,一个用于值。
我从客户端发送的内容似乎是正确的。 SOAP 数据包包含键数组和值数组的正确值。
对于两个数组,我在 WebService 端收到的内容(我可以在调用 WebMethod 时中断它)都是 null。不是空数组,只是 null。
为了将这些参数传递到 Web 服务,我尝试了很多方法(编码为 SerializedDictionary,尝试将键/值对塞入数据表中,尝试简单地使用两个字符串数组,然后将结果转换回WebService 端的正确类型),但我绝对没有运气。
所以我想总而言之,我的问题是:
有谁知道成功发送名称-值对的好方法,其中名称是字符串,值几乎可以是任何对象类型,但始终是 WebService WebMethod 的可序列化对象,以便它们的名称-值在服务端得到正确解释。
I am creating a webservice that essentially remotes some database calls (so that they happen over HTTP rather than the default SQL Server port of 1433).
Essentially what I have been trying to do is pass a number of parameters to a WebMethod on an ASMX WebService. The parameters are:
- A string representing the ID of the
query to be execute. - A DataTable
representing the structure of the
table that the information should be
filled into. - A dictionary of
parameters (i.e. name value pairs) to
be run with the query represented by
the ID above to get the expected
results. - A boolean which is
unimportant to this question
Now the problem I am having is that the string for the ID, the DataTable and the boolean are all coming through just fine, but the Dictionary does not. I know that by default, anything implementing IDictionary is not supported by XMLSerializing, so I have converted the dictionary into two object arrays, one for the keys, and one for the values.
What I'm sending through from the Client appears to be correct. The SOAP packet contains the correct values for both the keys array and the values array.
What I'm receiving on the WebService end (I can break in the WebMethod as it is called) is null for both of the arrays. Not an empty array, just null.
I have tried a lot of things in order to get these parameters across to the webservice (coded a SerializableDictionary, attempted to jam the key/value pairs into a data table, attempted to simply use two string arrays and then cast the results back into the correct types on the WebService end) but I've had absolutely no luck whatsoever.
So I suppose in summary, my question is:
Does anyone know a good way to successfully send Name-Value pairs where Name is a string, and Value can be almost any object type, but will always be a serializable object to a WebService WebMethod, such that they Name-Values are correctly interpreted on the service side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不完全确定问题是什么(可能是我自己的问题)
愚蠢)但我又从头开始,并实现了
具有 2 个数组的解决方案(键之一(字符串)和对象之一
(值))并且它按预期工作。
I'm not entire sure what the problem was (it may have been my own
stupidity) but I started from scratch again, and implemented the
solution with 2 arrays (one of keys (strings) and one of objects
(values)) and it worked as expected.
您提到该值可以是“几乎任何对象类型”,我怀疑这不会飞翔,并且可能是它破坏的地方,所有项目都必须可序列化。
尝试使用如下内容:
http://weblogs.asp.net /pwelter34/archive/2006/05/03/444961.aspx
You mention that the value can be "almost any object type", I suspect that's not going to fly and might be where it's breaking, the items all have to be serializable.
Try using something like this:
http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx