8

I have a web method with a signature like this:

public string[] ToUpper(string[] values)

I am using the 'Add Service reference' in Visual Studio 2010 to generate a reference to my service. Unfortunately, this process creates a proxy class called 'ArrayOfString' and uses this type instead of the expected 'string[]' type. The generated async service call signature ends up looking like this:

public void ToUpperAsync(Demo.ServiceReference.ArrayOfString values) { }
public void ToUpperAsync(Demo.ServiceReference.ArrayOfString values, object userState) { }

I have tried all the options of the 'Collection' drop down on the config service reference form and it doesn't seem the make a difference.

This was working previously, but for some reason it suddenly stopped working, perhaps after removing another web method from the service.

How do I get the generated service reference class to use the string[] type instead of a generated ArrayOfString type? Any help on this would be greatly appreciated.

EDIT: As @Oleg suggests, I am using ASMX web services.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Luke Baulch
  • 3,626
  • 6
  • 36
  • 44
  • perhaps your service method is returning list of string - have a look at http://stackoverflow.com/questions/505943/can-i-stop-my-wcf-generating-arrayofstring-instead-of-string-or-liststring – VinayC Feb 08 '11 at 05:08
  • @VinayC: I did read that question first, although the author asked for an answer to either of his two questions. I want to know the answer to the question "Is there a way to tell it not to generate ArrayOfString", which was not answered in that post. – Luke Baulch Feb 08 '11 at 06:10

3 Answers3

15

this change to XmlSerializer can ben done inside the Reference.svcmap file. Open it inside the Service Reference folder and change the Serializer xml node from "Auto" to "XmlSerializer" this solves the problem! Cheers

paketman
  • 169
  • 1
  • 3
5

I could reproduce your problem when adding a "Service reference" to an ASMX style web service. However when adding "Service refernce" to a WCF service or "Web reference" to an ASMX service argument was of type string[].

According to this I think that you can fix your problem by replacing "Service reference" by "Web reference".

Press "Advanced..." button on "Add service reference dialog". Add service reference

Press "Add web reference..." Advanced

Insert service url and add web reference Add web reference

Oleg Rudckivsky
  • 920
  • 6
  • 10
  • @Oleg: "Web References" use the old ASMX technology, which is considered by Microsoft to be a "legacy technology". – John Saunders Feb 13 '11 at 15:41
  • @John: You are 100% right, but as I understand Luke Baulch already has ASMX web service. As I mentioned in my answer the problem is only reproducable when using "Service Reference" with ASMX service. With WCF service everything is OK. That's why I assumed ASMX service is used and suggested "Web Reference" instead of "Service Reference". Another reason to think that legacy ASMX service is used is that in question "Web method" is mentioned but not an" Operation contract". – Oleg Rudckivsky Feb 13 '11 at 16:51
  • @Oleg: "two wrongs don't make a right". Just because ASMX is used on the servide doesn't mean it should be used on the client side. – John Saunders Feb 13 '11 at 18:11
  • @John: I completely agree with you and understand that rewriting service as WCF would be better solution. So you may think of my solution as some sort of simple hack. – Oleg Rudckivsky Feb 13 '11 at 19:10
  • @Oleg: I wasn't suggesting a rewrite. i was suggesting that, for such a small gain, it would be better to live with `ArrayOfString` rather than using a legacy technology where not necessary. – John Saunders Feb 13 '11 at 20:49
  • This is a great answer with a very clear solution. Thanks for finding the problem. Its also interesting reading the discussion between John and Oleg. If this is due to using older asmx web services, then I'll endeavor to move to the newer technologies when time permits. Once again, thanks. – Luke Baulch Feb 13 '11 at 23:28
  • @John: OK, I understand your opinion. Thanks for explaining it. – Oleg Rudckivsky Feb 14 '11 at 06:14
2

Too late but can help people in the future...

Use the svcutil and explicitly inform the command line util that you want the proxy class to be serialized by the XmlSerializer and not the DataContractSerializer (default). Here's the sample:

svcutil /out:c:\Path\Proxy.cs /config:c:\Path\Proxy.config /async /serializer:XmlSerializer /namespace:*,YourNamespace http://www.domain.com/service/serviceURL.asmx

Note that the web service is an ASP.NET web service ok?!

Fergara
  • 929
  • 8
  • 15