3

Not sure what I'm doing wrong but I have two services one is WCF and the other is a ASMX service.

I'm trying to call array of doubles the same way I did in my asmx version.

Here is an image of the two services:

enter image description here

I got a fix to being able to call that method but I would like to know why ArrayOfDouble isn't showing up the same way in my serviceref2 as my serviceref1?

This is the WCF version:

namespace WcfSum
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface SumListWCF
    {

        [OperationContract]
        string CalculateSum(List<double> listDouble);
    }
}

namespace WcfSum
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class SumList : SumListWCF
    {
        public string CalculateSum(List<double> listDouble)
        {
            return listDouble.Sum().ToString();
        }
    }
}

This is the ASMX version:

namespace CalculateWebServiceSum
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class SumList : System.Web.Services.WebService
    {
        [WebMethod]
        public string CalculateSum(List<double> listDouble)
        {
            return listDouble.Sum().ToString();

             //return listDouble.Select(n => (double)n).ToString();
        }
    }
}

Previous post was here: WCF array of doubles not called successfully

This provided the fix but doesn't explain why it doesn't operate the same way. Or if there was a way of getting it to act the same. Which makes me feel like im fundamentally missing something?

EDIT

P.s these are just running locally.

Community
  • 1
  • 1
G Gr
  • 6,030
  • 20
  • 91
  • 184
  • There's kind of a dirty little secret about WCF services: they are such a pain that nobody in the real world that I know of uses them if they have a choice. We create old fashioned ASMX, and when we add service references in VS2010, we go to Advanced->Add Web Reference so things work the way you expect. – Eric Z Beard Mar 15 '12 at 18:56
  • 2
    WCF services are different from ASMX services. Why are you surprised that they are different? – Stilgar Mar 15 '12 at 19:11
  • 3
    Lots of people I know use WCF in the "real world", I don't know what the fuss is about, they are just slightly different. I would favor WCF since it is most likely to have continued support and improvements by Microsoft. http://keithelder.net/2008/10/17/WCF-vs-ASMX-WebServices/ – Kekoa Mar 15 '12 at 19:13
  • That cant be true? Plus I tryed the advanced option to add web ref's doesnt work at all the way I would want. Would be really nice if you could visually just add a web reference and add in the methods you wanted. Im sure its the service and operation contracts bit I have wrong. – G Gr Mar 15 '12 at 19:13
  • @Garrith I don't see `ArrayOfDouble` anywhere in the code. If the type is not referenced in the interface, it's not going to show up in the service reference. – Kekoa Mar 15 '12 at 19:19
  • Not sure what you mean? `Webservices09004961.SumListSOAP.ArrayOfDouble a = new Webservices09004961.SumListSOAP.ArrayOfDouble();` This is how its called with asmx I didnt define it in asmx either anywhere in the code. – G Gr Mar 15 '12 at 19:31
  • @EricZBeard: that is a very strange statement of yours. I for one have **dozens** of production WCF services running day in, day out - and I would **NEVER** go back to ASMX unless someone put a gun to my head .... – marc_s Mar 15 '12 at 19:47

2 Answers2

4

There is nothing in the SOAP or WSDL standards that specifies how something like a List<double> should be serialized. ASMX apparently invented a complexType in the XML schema to represent array of double.

WCF is much better than ASMX. When you use "Add Service Reference", you get to decide how to handle repeated elements like your array of doubles. You can choose for them to be treated as an array, as a List<T>, etc.

There would be negative value in restricting WCF to the limitations of ASMX, which is a legacy technology.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
0

You are using a generic List<> parameter, which is not supported for asmx and wcf due to interoperability with languages that do not support generic collections. See also these questions.

This question mentions a generated ArrayOfInt, so the ArrayOf* type name may be a, uhm, generic solution to deal with generic types.

Community
  • 1
  • 1
devio
  • 36,858
  • 7
  • 80
  • 143