Consume an asmx service from a Rest

Asked

Viewed 44 times

1

How do I pass an object I have in a REST for a ASMX? I have this controller in REST that has the object(client) that I want to send to a ASMX

[Route("api/[controller]")]
public class OptOutClientController : Controller
{
   HttpClient client = new HttpClient();
   private readonly IOptOutService _service;
   public OptOutClientController(IOptOutService service)
   {
        _service = service;
   }

   [HttpPost]
   public OptOutCliente Unsubscribe([FromBody]OptOutCliente cliente)
   {
      if (cliente == null)
         throw new OptOutException("Informar os dados do cliente OptOut!");

      var valida = _service.Process(cliente);

      BasicHttpBinding httpBinding = new BasicHttpBinding();
      EndpointAddress wsUrl = new 
             EndpointAddress("http://localhost:64460/meuservico.asmx");

      //ServicoWSClient soapClient = new ServicoWSClient(httpBinding, wsUrl);

      return cliente;
  }
}

How do I pass this client across?

  • When you add the reference to the external service it "imports" the reflection/contract classes used by it, as well as creates the Client class, commented on in your code

  • @Leandroangelo, let me get this straight. The class Servicowsclient is an existing class in the service to be consumed, certain?

  • 1

    it is generated when you add the service reference. It is either that or you will need to do an XML post specified in wsdl, as well as do the XML pair you will receive in return

  • 1

    This can be done via the service reference: https://msdn.microsoft.com/pt-br/library/bb628649.aspx. Or this example can be equal: https://answall.com/questions/5670/consumr-webservice-dynamically

No answers

Browser other questions tagged

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