Todd Bowles
Todd Bowles

Reputation: 1574

How to Pass Name/Value Pairs to an ASMX Web Method?

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:

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.

Upvotes: 3

Views: 3753

Answers (2)

Todd Bowles
Todd Bowles

Reputation: 1574

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.

Upvotes: 3

Doobi
Doobi

Reputation: 4842

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

Upvotes: 2

Related Questions