WCF массив пар не успешно вызывается - PullRequest
0 голосов
/ 13 марта 2012

Таким образом, мне удалось без проблем использовать SOAP, но у меня возникли проблемы с использованием WCF для выполнения той же работы.

Мое приложение получает список чисел, а затем суммирует их с помощью веб-службы, я могу успешно сделать это с помощьюSOAP, но теперь я сталкиваюсь с проблемами при попытке сделать это с WCF.

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

Обратите внимание, что я вызываю клиентский метод так же, как кажется, это нормально.

Однако, когда я пытаюсь использовать тот же метод, яне могу вызвать ArrayOfDoubles, как мой предыдущий метод с использованием мыла:

        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);

Моя проблема, я боюсь, заключается в моем методе wcf, Service1.svc.cs выглядит так:

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мне кажется нормально?Мой IService, возможно, это проблема, это все, что у меня есть для этого:

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);

    }

Обычно я ожидаю, когда я наберу Myservice.ServiceReference1.arrayofdoubles появится, но у меня нет этой опции, на этот раз я получаю только Service1 или serviceclient.

РЕДАКТИРОВАТЬ

Чтобы уточнитьabit more, потому что я использую этот метод (потому что ArrayOfDoubles там не похож на мою закомментированную версию мыла)

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

Я получаю сообщение об ошибке:

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

В этой строке в AddRange.

arrayOfdoubles.AddRange(myArrai12);

Я изо всех сил пытаюсь выяснить, почему:

Webservices09004961.ServiceReference2. не покажет ArrayOfDoubles Как это происходит с моей версией мыла.

Это может помочь показать, что происходит:

enter image description here

1 Ответ

1 голос
/ 13 марта 2012

ОК, некоторые исправления:

    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);

Очевидно, arrayOfdoubles не очень хорошее имя (это прокси клиента), но я оставил его как ссылку на ваш код.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...