Can I stop service reference generating ArrayOfString instead of string[]?

做~自己de王妃 提交于 2019-11-28 07:27:35

问题


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.


回答1:


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".

Press "Add web reference..."

Insert service url and add web reference




回答2:


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




回答3:


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?!



来源:https://stackoverflow.com/questions/4929735/can-i-stop-service-reference-generating-arrayofstring-instead-of-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!