Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Erro ao tentar incluir um cliente através do projeto ConsumindoServiço

Olá pessoal, tudo bom ?

Estou tentando resolver um problema que ocorre nas funcionalidades Buscar e Salvar. Ao tentar salvar é lançado uma exception que mostra a seguinte mensagem:

================
Não havia um ponto de extremidade em escuta em http://localhost:8088/cliente capaz de aceitar a mensagem. 
Em geral, isso é causado por um endereço ou ação de SOAP incorreta. Consulte InnerException, 
se presente, para obter mais detalhes.
===============

Abaixo o código do form.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ConsumindoServico.ServiceReference1;

namespace ConsumindoServico
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSalvar_Click(object sender, EventArgs e)
        { 

            try
            {
                ClienteServiceClient servico = new ClienteServiceClient();
                Cliente clienteCadastro = new Cliente();
                clienteCadastro.Nome = txtNome.Text;
                clienteCadastro.Cpf = txtCpf.Text;
                servico.Add(clienteCadastro);

                MessageBox.Show("Cliente cadastrado com sucesso");

                txtNome.Text = txtCpf.Text = string.Empty;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show(ex.Message);
                Console.ReadLine();

            }


        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            string nome = txtNome.Text;

            try
            {
                ClienteServiceClient servico = new ClienteServiceClient();
                Cliente cliente = servico.Buscar(nome);
                txtCpf.Text = cliente.Cpf;
                txtNome.Text = cliente.Nome;


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Console.ReadLine();
            }
        }
    }
}

ClienteSer vice.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Passagens
{
    public class ClienteService : IClienteService
    {
        ClienteDAO dao;

        public ClienteService()
        {
            dao = new ClienteDAO();
        }

        public bool Add(string nome, string cpf)
        {
            Cliente c = new Cliente();
            c.Nome = nome;
            c.Cpf = cpf;
            dao.Add(c);
            return string.IsNullOrEmpty(nome) ? false : true;
        }

        public Cliente Buscar(string nome)
        {
            return dao.Buscar(nome);
        }
    }
}

IClienteService.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Threading.Tasks;

namespace Passagens
{
    [ServiceContract]
    public interface IClienteService
    {
        [OperationContract]
        Cliente Buscar(string nome);
        [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, 
                   UriTemplate = "addCliente/{Nome};{Cpf}")]
        bool Add(string nome, string cpf);
    }
}
3 respostas

Cesar, voce conseguiu resolver?

Senao, pode mandar a stack completa junto com a inner exception?

Olá Paulo, ainda não ! Segue a descrição do erro :

System.ServiceModel.EndpointNotFoundException: Não havia um ponto de extremidade em escuta em http://localhost:8088/cliente capaz de aceitar a mensagem. Em geral, isso é causado por um endereço ou ação de SOAP incorreta. Consulte InnerException, se presente, para obter mais detalhes. ---> System.Net.WebException: O servidor remoto retornou um erro: (404) Não Localizado.
   em System.Net.HttpWebRequest.GetResponse()
   em System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- Fim do rastreamento de pilha de exceções internas ---

Server stack trace: 
   em System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   em System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   em System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   em System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   em System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   em System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   em System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   em System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   em System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   em ConsumindoServico.ServiceReference1.IClienteService.Add(Cliente c)
   em ConsumindoServico.ServiceReference1.ClienteServiceClient.Add(Cliente c) na C:\Pessoal\Faculdade\softblue\alura\WCF_Distribuindo_Sistemas\Passagens\ConsumindoServico\Service References\ServiceReference1\Reference.cs:linha 130
   em ConsumindoServico.Form1.btnSalvar_Click(Object sender, EventArgs e) na C:\Pessoal\Faculdade\softblue\alura\WCF_Distribuindo_Sistemas\Passagens\ConsumindoServico\Form1.cs:linha 30
solução!

O buscar funciona?

Eu acho que o erro está aqui:

http://localhost:8088/cliente

Deveria ser addCliente nao?

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software