2

I have a ASP.NET web service (.asmx) with methods that receives int arrays (int[]) and nullable int arrays (int?[]) as parameters. I also have a test web application for consuming this web service via a Service Reference.

The problem is that every time I change something in the web service code, recompile it and update the service reference at the test application, a different type of parameter is generated for the web service methods on the test application. For example:

On the first build and service update, the method signature generated by Visual Studio at the test app is:

void MyMethod(int[] firstParam, int?[] secondParam).

Then I make some changes, do it again and get something like:

void MyMethod(ArrayOfInt fistParam, ArrayOfInt1 secondParam)

(with ArrayOfInt being the equivalent of int[] and ArrayOfInt1 being the equivalent of int?[]).

Once more, and I get:

void MyMethod(ArrayOfInt1 firstParam, ArrayOfInt secondParam),

with ArrayOfInt and ArrayOfInt1 swaped (ArrayOfInt1 being now the equivalent of int[] and ArrayOfInt being the equivalent of int?[]).



What I really want is to use the simple int[] and int?[] types (no matter how many times I recompile and update the service reference!). How can I achieve this?

Raphael
  • 1,847
  • 1
  • 17
  • 29
  • Does no one ever found the reason for this? Does no one ever got annoyed with this silly behavior? – Raphael Aug 25 '11 at 13:45
  • 1
    Are you using ASP.NET (asmx) web services, or WCF? – CodingWithSpike Sep 26 '11 at 12:39
  • Sounds like you should turn on WCF – Seb Sep 26 '11 at 12:42
  • I'm using ASP.NET, and I can't turn to WCF yet (for business reasons). – Raphael Sep 26 '11 at 16:47
  • ...may this is simply impossible?... – Raphael Oct 04 '11 at 13:47
  • 1
    Silly, but you can avoid by creating your own collection array class and using it in method as arguments, compiler won't interfere then. – hungryMind Oct 17 '11 at 14:37
  • Its doubtful you will return but could you post exactly what you get because your two examples are exactly the samething. – Security Hound Oct 17 '11 at 15:54
  • @Ramhound, why do you think that? In the first example, the method gets the desired signature. In the second one, the `int[]` type is replaced by the `ArrayOfInt` type, and the `int?[]` type is replaced by the `ArrayOfInt1` type, causing the code to break. In the third one, the `ArrayOfInt` type is replaced by the `ArrayOfInt1` type, and vice-versa, causing the code to break again. – Raphael Oct 17 '11 at 17:56

2 Answers2

0

I know this is old, but I just ran across the same issue. The difference for me was adding a web reference rather than a service reference.

Within VS, perform the following:

  1. Right-click, select Add > Service Reference
  2. Click the Advanced button in the lower left
  3. Click the Add Web Reference button in the lower left
  4. Add the URL and reference name then click Add Reference

My web reference properly added the method with int[] parameter.

EDIT: Here is a better answer with pretty pictures to illustrate!

EDIT 2: This answer gets rid of the ArrayOfXXX to List<XXX> silliness and doesn't use the legacy tech, so win-win as far as I am concerned. Now, how to do this within the tooling? Or is it only something you can do by editing the file directly?

Community
  • 1
  • 1
Tim Hobbs
  • 2,017
  • 17
  • 24
  • Bad idea. Try specifying the type for collections in "Add Service Reference". It makes little sense to go back to using a legacy technology just to get `int[]` as a parameter type. – John Saunders Nov 21 '14 at 21:02
  • For my situation it already is an ASMX file, so not really "going backwards" - there is no back to go to. The OP also talks about it being an ASMX file. If I am not gaining the benefits of WCF I don't really see why I need to worry about it. If I needed more I wouldn't be using ASMX in the first place. :) – Tim Hobbs Nov 22 '14 at 04:13
  • No, your _service_ is ASMX. That's no reason for the _client_ to be ASMX. – John Saunders Nov 22 '14 at 12:12
  • Yep, but there is no reason for my client to be WCF either. I don't need anything other than what ASMX offers and "just because" isn't a good enough reason. There aren't any performance issues I have to worry about that could maybe make WCF a better alternative, I don't have any security concerns that maybe WCF would make better, I don't have _any_ real reason that SOAP doesn't work perfectly well for me here. I am someone that **does** care for best practices, but there are also opportunities to not over-engineer for the sake of it - for me this is one of those times. – Tim Hobbs Nov 25 '14 at 23:24
  • WCF would be using SOAP. FYI, the main reasons I would suggest are: 1) Lack of support from Microsoft for ASMX bug and security fixes, and 2) The ease of turning on WCF tracing when you want to know what's going on. It's just a config change. – John Saunders Nov 25 '14 at 23:26
  • Yeah, I get you. It really is just a matter of needs with this situation. It is an internal thing, rarely used and it works. If I have to revisit it at all I'd certainly reconsider, but as I said I don't feel the "benefits" do anything for me here. I have another similar situation right now with something else and getting it to work "the WCF way" is actually more of a bother - this too is just a small, pretty insignificant service. I'll learn a bit, so that is good, but it is more of a PITA right now than it is helpful - but it is the "right" way so I guess that makes it okay... – Tim Hobbs Nov 25 '14 at 23:32
0

Try using wsdl.exe tool to generate web service proxy instead using Visual Studio.

This work for me!

  • What makes you think this would solve his problem? Did you have this problem, then solved it by using wsdl.exe? – John Saunders Nov 28 '11 at 19:06
  • Yes, when I use wsdl.exe, I can use int[] instead ArrayOfInt(). – Alberto Fojo Nov 29 '11 at 09:02
  • It worked fine, but I was looking for a solution inside Visual Studio. If no one gives a solution for this, I'll accept this answer, for I think Visual Studio simply can't do this. – Raphael Dec 12 '11 at 14:18
  • Well, I think there isn't a solution for this inside Visual Studio... so using wsdl.exe works fine as a workaround. Thanks all for the effort! – Raphael Dec 15 '11 at 14:05