Consume SOAP from a Rest in Asp.Net Core 2.0

Asked

Viewed 1,250 times

0

I re-asked 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 that 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 SOAP and pass the values of the parameter client. This parameter comes from another service and it is working (at least in Postman), because the Postman simulates this other service. I don’t know how I do it.

Difficulty Rest is json and Soap is xml.

  • I don’t understand what your question is...

  • @Leandroangelo, it’s how I consume a SOAP. What I call the wcf service(Soap)

1 answer

2

The easiest way is to add the reference to System.Service.Model of an older version of . Net (prior to 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;
}
  • Leandro, do I need to add any references via Nuget or Framework? My service is: http://localhost:64460/Service1.svc and Servicowsclient What’s that? I’m hard at it

  • Hmmm you are consuming a WCF, not a Classic Soap and the service is your same... Its class is Service1 same? Ps.: Servicows is just a fictional name I used as example...

  • Hello Leandro, just correcting, I talked to the bus staff is the service is a asmx and not svc as I commented above. I’m sorry for the mess I made.

Browser other questions tagged

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