WCF out bool parameter

Asked

Viewed 113 times

2

I created a Webservice WCF, and at the interface IService1.cs I put the signature of the methods

[ServiceContract]
public interface IService1 {
     [OperationContract] bool insertConsulta(BConsulta bCos);
     [OperationContract] bool alterConsulta(BConsulta bCos);
}

From there I implemented this interface on the web service Service1.svc, and stayed like this

public class Service1 : IService1 {
     NConsulta nCos = new NConsulta();
     public bool insertConsulta(BConsulta bCos) {
        return nCos.insertConsulta(bCos);
     }
     public bool alterConsulta(BConsulta bCos) {
        return nCos.alterConsulta(bCos);
     }
}

Then I referenced the Web Service to the project and put as the name of this reference as localhost.

In Windows Form I installed Webservice

localhost.Service1 service = new localhost.Service1();

The following problem when I want to consume the web service it gives an error in the methods of the web service that has return bool, on the interface I ask 1 parameter and when I put service.insertConsulta(bCos);, he asked but 2 wall and says the following:

void Service1.insertConsulta(BConsulta bCos, out bool insertConsultaResult, out bool insertConsultaResultSpecified)

The other methods that have as return void work normally, but those who have boolean return appears this error, Dai I do not know what to do !

1 answer

1


Instead of using the option to add the reference to a Web Service, try using the option to add reference to a "Service Reference". The first is the option for services. ASMX (old), while the latter is the option that works best with WCF.

Note that what you have now should work - if you call the service as in the code below you will have the result of the call in the variable resultado.

bool resultado, naoUsado;
service.insertConsulta(bCos, out resultado, out naoUsado);
if (resultado) { ... }
  • I’m putting this event at the click of a button, then an error appeared Cannot implicity convert type void to bool

  • You may not use the call to service.insertConsulta an if (like if (service.insertConsulta(...)) - since the method returns nothing. I updated the answer with what you can do. Or you can recreate the reference using the Add Service Reference instead of the Add Web Service Reference.

  • Stopped giving error, but when I run it does not work

Browser other questions tagged

You are not signed in. Login or sign up in order to post.