I have a problem that I really need solved in any way (changing data types is an option)
Assumptions:
- Both Program and Service done in VS2008
- I have complete control over both Program and Service
- I have a program that is passing a “list” of info to the Service Reference
Example:
Program snippet:
IList<string> XMLList = null;
XMLList = new List<string>();
// fill my list up here... mostly just an "array" of xml-based strings
string[] arrayToSend = new string[XMLList.Count];
arrayToSend = XMLList.ToArray<string>();
string results = DataFeedService.ProcessXMLBatch(arrayToSend);
Service Snippet:
[WebMethod]
public string ProcessXMLBatch(string[] XMLBatch)
{
// process the xml here...
return "done";
}
Problem:
It does not consider the string[] that I create in the service to be the same kind of
string array. It converts it to a type of #namespace.#servicename.ArrayOfString
this code will currently not compile. I have looked around for alternate ways to pass a list or a generic and I keep hitting roadblocks.
Consider changing your code to use a
List<string>rather than anIList<string>(I know that’s what you’re actually using, but declare your variable as such). TheList<T>class provides an explicitToArray()function that will be faster than theEnumerable.ToArray<T>extension method you’re employing in your code. This might clear up your issues too, but I’m not certain about that.Also, you do not need
Just declare it as
You’re already assigning it with the
ToArray()call; no need to create another one beforehand.Edit Why not instantiate and populate the
ArrayOfStringclass that’s created in your service reference namespace? It will work just like aList<string>(and, in fact, I believe it inherits from it). Use this as the type for yourXMLList, and just send theXMLListvariable directly to the function.