Ok, I had actually previously figured out that I had to write a simple web
method that returns an instance of the StringKeyStringValue type in order
for a corresponding stub definition to be included in References.cs
In the webservices newsgroup, it was suggested to me that I modify
References.cs to delete this stub definition and include the following line
of code:
using UtilityStorageLibrary;
"UtilityStorageLibrary" is the namespace used in my custom class library
that contains the definition of the StringKeyStringValue type
The logic is that any StringKeyStringValue objects returned by web-methods
will be received by the proxy class and on deserialization will be converted
into instances of the local StringKeyStringValue type.
I made these changes, and I no longer receive any compile-time or run-time
errors ...
However,
Object[] array = WebReference1.WebService1.WebMethod1();
StringKeyStringValue sksv = (StringKeyStringValue) array[0];
String s1 = sksv.Key;
String s2 = sksv.Value;
reveals that sksv.Key and sksv.Value are both null
So, apparently sending across an array of instances of a custom type is a
bit more tricky than sending across a single instance of a custom type.
"Dale Preston" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> As I mentioned in the response to your third post today, you have to make
> your client and web service talk the same language about
> StringKeyStringValue objects. What you have is like identical twin
> objects.
> Exactly alike but not the same object. On the client side, change the
> declaration of arrayElement like this:
>
> WebReference1.WebService1.StringKeyStringValue arrayElement = null;
>
> There are comments in my second article about how to use the local copy of
> a
> class by modifying the reference.cs. If your class is not listed in
> Reference.cs I assume it is because your class is either not public or not
> returned by a web method. So create a web method that returns a
> StringKeyStringValue object.
>
> HTH
>
> Dale Preston
>
>
>
> "John Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
> news:(E-Mail Removed)...
>> Hi Dale, and thanks for the response.
>>
>> Object[] array = null;
>> ListItem listItem = null;
>> StringKeyStringValue arrayElement = null;
>> WebReference1.WebService1 webService = null;
>>
>> webService = new WebReference1.WebService1();
>>
>> array = webService.Method1();
>> for (int i=0; i < array.Length; i++)
>> {
>> arrayElement = (StringKeyStringValue) array[i];
>> listItem = new ListItem();
>> listItem.Value = arrayElement.Key;
>> listItem.Text = arrayElement.Value;
>> RadioButtonList1.Items.Add(listItem);
>> }
>>
>>
>>
>> "Dale Preston" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Can you show the code that calls the web service and the code that
> access
>> > the array afterwards?
>> >
>> > In the mean time, here's my short tutorial on returning objects from
>> > web
>> > services and solutions to some of the problems that come up doing so.
>> >
>> > http://www.dalepreston.com/Blog/Arch...6_Archive.html and
>> >
>> > http://www.dalepreston.com/Blog/Arch...4_Archive.html.
>> >
>> > HTH
>> >
>> > Dale Preston
>> > MCAD, MCDBA, MCSE
>> >
>> > "John Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
>> > news:(E-Mail Removed)...
>> >> make a call to XML Web Service WebMethod ... returns object[] myArray
>> >> with
>> >> no error ...
>> >>
>> >> myArray[] contains objects of type StringKeyStringValue
>> >>
>> >> runtime error occurs on accessing properties of myArray[i]
>> >>
>> >> <<<
>> >> ex.Message "Server was unable to process request. --> There was an
> error
>> >> generating the XML document. -->
>> > UtilityStorageLibrary.StringKeyStringValue
>> >> cannot be serialized because it does not have a default public
>> > constructor."
>> >> >>>
>> >>
>> >>
>> >> using System;
>> >> using System.Runtime.Serialization;
>> >> using System.Runtime.Serialization.Formatters.Binary;
>> >> using System.Runtime.Serialization.Formatters.Soap;
>> >>
>> >> namespace UtilityStorageLibrary
>> >> {
>> >> [Serializable()]
>> >> public class StringKeyStringValue
>> >> {
>> >> private String stringKey = null;
>> >> private String stringValue = null;
>> >>
>> >> public StringKeyStringValue()
>> >> {
>> >> }
>> >>
>> >> public StringKeyStringValue(String stringKey, String stringValue)
>> >> {
>> >> this.stringKey = stringKey;
>> >> this.stringValue = stringValue;
>> >> }
>> >>
>> >> public string Key
>> >> {
>> >> get
>> >> {
>> >> return stringKey;
>> >> }
>> >> }
>> >>
>> >> public string Value
>> >> {
>> >> get
>> >> {
>> >> return stringValue;
>> >> }
>> >> }
>> >>
>> >> }
>> >> }
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>>
>>
>
>