Consume SOAP from a rest in Asp.Net Core 2.0

0

I refined the question, trying to improve it for better understanding.

1) I created a WCF service, called OptOutService.svc. In this service I have an interface and a class that implements this interface, as below:

[ServiceContract]
public interface IOptOutService
{
   [OperationContract]
   [WebInvoke]
   void PostOptOut(OptOutEntity cliente);
}

and the class

[CollectionDataContract]
public class OptOutService : IOptOutService
{
    public void PostOptOut(OptOutEntity cliente)
    {
        throw new NotImplementedException();
    }
}

And my model

[DataContract]
public class OptOutEntity
{
    [DataMember]
    public Int64 Cpf { get; set; }
    [DataMember]
    public String Email { get; set; }
    [DataMember]
    public String Telefone { get; set; }
    [DataMember]
    public String Bandeira { get; set; }
    [DataMember]
    public String Canal { get; set; }

    public OptOutEntity(Int64 cpf, string email, string telefone, string bandeira, string canal)
    {
       Cpf = cpf;
       Email = email;
       Telefone = telefone;
       Bandeira = bandeira;
       Canal = canal;
     }
}

I need in the client parameter, I get the information in another service that was done in Asp.Net Core 2.0 (REST) Here is the controller code

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

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

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

  return cliente;
}

That is, I need this service to consume the SOAP and pass the values of the client parameter. This parameter comes from another service and it is working (at least in postman) because Postman simulates this other service. I do not know how I do it.

Difficulty Rest is json and soap is xml.

    
asked by anonymous 22.06.2018 / 15:07

1 answer

2

The easiest way is to add the reference to System.Service.Model of an older version of .Net (pre-core) and consume the service via BasicHttpBinding

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

    BasicHttpBinding httpBinding = new BasicHttpBinding();
    EndpointAddress wsUrl = new EndpointAddress("http://www.endereco.net/ServicoWS.asmx");

    ServicoWSClient soapClient = new ServicoWSClient (httpBinding, wsUrl);

    //Aqui você estará com o endpoint configurado e poderá executar os métodos que quiser      

    return cliente;
}
    
22.06.2018 / 16:15