0

So I managed to use SOAP no problem but I am having difficulty using WCF to do the same job.

My application takes a list of numbers then sums them using a webservice, I can successfuly do this using SOAP but now I am running into trouble trying it with WCF.

        Webservices09004961.ServiceReference1.Service1SoapClient SumCLient = new ServiceReference1.Service1SoapClient();
        Webservices09004961.ServiceReference2.IService1 SumClientWCF = new ServiceReference2.Service1Client();

Notice that I call the client method the same way this seems fine.

However when I try the same method I cannot seem to call ArrayOfDoubles like my previous method using soap:

        Webservices09004961.ServiceReference2.Service1Client arrayOfdoubles = new ServiceReference2.Service1Client(); //this line is wrong but I tryed it anyway
        //Webservices09004961.ServiceReference1.ArrayOfDouble arrayOfDoubles = new Webservices09004961.ServiceReference1.ArrayOfDouble(); 
        arrayOfDoubles.AddRange(myArrai12);
        string f = SumCLientWCF.CalculateSum(arrayOfDoubles);
        Console.WriteLine("The sum total equals: " + f);

My problem I fear lies in my wcf method, Service1.svc.cs looks like this:

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 Service1 : IService1
    {
        public string CalculateSum(List<double> listDouble)
        {
            return listDouble.Sum().ToString();

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

        }
    }
}

This seems fine to me? My IService tho may be the problem this is all I have for it:

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 IService1
    {

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

    }

Normally I would expect once I type Myservice.ServiceReference1. arrayofdoubles would come up but I dont have that option this time the only option I am getting is Service1 or serviceclient.

EDIT

To clarifify abit more because I use this method (because ArrayOfDoubles isnt there like with my soap version commented out)

    Webservices09004961.ServiceReference2.Service1Client arrayOfdoubles = new ServiceReference2.Service1Client(); //this line is wrong but I tryed it anyway
    //Webservices09004961.ServiceReference1.ArrayOfDouble arrayOfDoubles = new Webservices09004961.ServiceReference1.ArrayOfDouble(); 

I get the error message:

Error   1   'Webservices09004961.ServiceReference2.Service1Client' does not contain a definition for 'AddRange' and no extension method 'AddRange' accepting a first argument of type 'Webservices09004961.ServiceReference2.Service1Client' could be found (are you missing a using directive or an assembly reference?)

On this line under AddRange.

arrayOfdoubles.AddRange(myArrai12);

Im struggling to find out why:

Webservices09004961.ServiceReference2. wont show ArrayOfDoubles Like it does with my soap version.

This might help show whats going on:

enter image description here

G Gr
  • 6,030
  • 20
  • 91
  • 184
  • Your sum-of-doubles is a string?? – H H Mar 12 '12 at 23:07
  • You know, I would gladly trade all those namespaces for a little bit of the error message. Right now it's not even clear if you have a runtime or a compiletime error. – H H Mar 12 '12 at 23:09
  • If you have it working with SOAP then are you sure you don't have it working with WCF? You need to be more specific about what you have working... – M.Babcock Mar 12 '12 at 23:09
  • Hi guys ive updated. I initially thought it was my wcf method because I couldnt call ArrayOfDoubles like I did with my soap version. And I have did everything the exact same just a change in my webservice? – G Gr Mar 12 '12 at 23:23
  • I put the servicereference1 in just to show you my previous method of using it with soap just incase it might confuse. – G Gr Mar 12 '12 at 23:29
  • What do you mean "your SOAP version"? Do you mean ASMX? – John Saunders Mar 12 '12 at 23:39

1 Answers1

1

OK, some fixes:

    var arrayOfdoubles = new ServiceReference2.Service1Client(); 
    var inputData = new List<double> { 1.1, 2.2 };
    string f = arrayOfdoubles.CalculateSum(inputData);
    Console.WriteLine("The sum total equals: " + f);

Obviously arrayOfdoubles is not a very good name (it's the client proxy) but I left it as a reference to your code.

H H
  • 263,252
  • 30
  • 330
  • 514
  • Hey Henk thanks very much that works but why didnt my method work the same one I used for the soap? I mean it should show my ArrayOfDoubles thats really annoying me now but your method is also good. (Least we know it works) – G Gr Mar 12 '12 at 23:54
  • Hey Henk I uploaded an image of the service references I noticed it didnt show my ArrayOfDouble like my soap version. Why is that? – G Gr Mar 13 '12 at 00:02