none
How do i do to consume a soap service from rest api RRS feed

  • Question

  • This is my OptOutService.svc

    Interface

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

    My Class

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

    My Model

    [DataContract]
        public class OptOutModel
        {
            [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 OptOutModel(Int64 cpf, string email, string telefone, string bandeira, string canal)
            {
                Cpf = cpf;
                Email = email;
                Telefone = telefone;
                Bandeira = bandeira;
                Canal = canal;
            }
        }

    Below my Rest Service(Controller)

    [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/OptOutService.svc");

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

                return cliente;
            }

    I want to consume the Soap Service and to pass an object from REST(cliente object) to SOAP Service. How can I do this? 

    The parameter cliente in the SOAP will go to receive the object cliente from REST.


    • Edited by pnet Friday, June 22, 2018 9:00 PM
    Friday, June 22, 2018 4:03 PM

All replies

  • Hi pnet,

    Have you enabled both SOAP and Rest endpoint for “OptOutService.svc”?

    Do you receive any error with your current code?

    I would suggest you generate the client code for OptOutService.svc, and then call it from Console app first, will it work?

    If it works, you could try the same code in Rest Service. If not, share us the issue you got.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 25, 2018 5:57 AM
  • Hi Thao, thanks for reply. I said that i would consume a SVC from REST, but doesn't SVC(WCF) but **asmx service**. I did a svc example, cause i thought svc, but is a asmx service to consume from rest(asp.net core). I'll go to edit my post.  
    Monday, June 25, 2018 1:07 PM
  • Hi pnet,

    For consuming asmx service from .net core, I would suggest you try WCF Service Provider.

    https://docs.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide

    After generating the client code in .net core, you could try code below:

                ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient(EndpointConfiguration.WebService1Soap);
                var response = await client.HelloWorldAsync();
                var result = response.Body.HelloWorldResult;
    

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 26, 2018 6:10 AM