Service does not rise

-3

I have a service [file.svc.cs] but it does not go up, I try to access it with ajax and it's not found. Anyone know how to solve this, what could be wrong.?

namespace Bob.Servico
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Usuario" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Usuario.svc or Usuario.svc.cs at the Solution Explorer and start debugging.
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Usuario : IUsuario
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public GetUsuarioDAO GetUsuario(GetUsuarioRequestDAO usuario)
        {
            log.Info("Iniciando GetUsuario");
            var retorno = new GetUsuarioDAO();

            using (var db = new BobDataContext())
            {

                var result = db.sp_usuario_select(null, usuario.email, usuario.cpf, usuario.senha).Select(r => new GetUsuarioDAO()
                {
                    email = r.email,
                    cpf = r.cpf,
                    nome = r.nome,
                    nome_usuario = r.nome_usuario,
                    sexo = r.sexo,
                    data_nascimento = Convert.ToString(r.data_nascimento),
                    id = r.id,
                    celular = r.celular,
                }).FirstOrDefault();

                if (result != null)
                {
                    retorno = result;
                    log.Info("GetUsuario - OK");
                    retorno.mensagens.Add(new MensagemDAO() { Mensagem = "OK", Tipo = Models.Enum.TipoMensagemEnum.Sucesso });
                }
                else
                {
                    if (string.IsNullOrEmpty (usuario.facebook_id) ){
                        log.Info("GetUsuario - nOK - Usuário ou senha inválidos.");
                        retorno.mensagens.Add(new MensagemDAO() { Mensagem = "Usuário ou senha inválidos!.", Tipo = Models.Enum.TipoMensagemEnum.Erro});

                    }
                    else
                    {
                        log.Info("GetUsuario - OK - Não encontrou nenhum usuário.");
                        retorno.mensagens.Add(new MensagemDAO() { Mensagem = "0", Tipo = Models.Enum.TipoMensagemEnum.Aviso });

                    }

                }
            }

            return retorno;
        }

    }
}

function inicio() {
  $("span.help-block").hide();
  alert("2");
  $(document).on("click", "#btn_esqueci_senha", function() {
    window.location = "esqueci-senha.html";
  });

  $(document).on("click", "#btn_validar", function() {

    $("#aviso").hide();
    $("#aviso").find("p").html("");

    if (validar()) {
      alert("3");
      var email = null;
      var cpf = null;

      if ($("[name=email]").val() == "" || $("[name=email]").length == 0) {
        cpf = $("[name=cpf]").val();
      } else {
        email = $("[name=email]").val();
      }

      var usuario = {
        email: email,
        cpf: cpf,
        senha: $("#txt_senha").val()
      };

      //var usuario = getFormData($("#usuario"));
      alert(email);
      $.ajax({
        type: "POST",
        url: "../sistema/Bob.Servico/Usuario.svc.cs/GetUsuario",
        cache: false,
        //crossdomain:true,
        contentType: "application/json",
        processData: false,
        dataType: "json",
        data: JSON.stringify(usuario),
        success: function(data) {

          alert("teste zombie 4 :( ");

          console.log(data);
          if (data.GetUsuarioResult.mensagens[0].Mensagem == "0") {
            window.location = "dados-complementares.html";
          } else if (data.GetUsuarioResult.mensagens[0].Mensagem == "OK") {

            window.localStorage.setItem("usuario", JSON.stringify(data.GetUsuarioResult));
            window.location = "home.html";
          } else {
            alert(data.GetUsuarioResult.mensagens[0].Mensagem);
          }
        },
        error: function(error) {
          alert(error)
        }

      });

    }
  });


}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">
  <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
  <link rel="stylesheet" type="text/css" href="css/index.css">
  <title>site</title>

  <!-- Bootstrap 3.3.6 -->
  <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">

  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <link rel="stylesheet" href="dist/css/custom.css">

  <!-- iCheck -->
  <link rel="stylesheet" href="plugins/iCheck/square/blue.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script><scriptsrc="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
      <![endif]-->
</head>

<body onload="onDeviceReady()">

  <div class="container-fluid">

    <div class="wrapper">

      <!-- Main Header -->
      <header class="main-header">

        <!-- Logo -->
        <a href="home.html" class="logo">
          <!-- mini logo for sidebar mini 50x50 pixels -->
          <span class="logo-mini"></span>
          <!-- logo for regular state and mobile devices -->
          <span class="logo-lg"></span>
        </a>
        <!-- Header Navbar -->

      </header>

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <div class="row">

            <div class="div-beta"></div>

            <div class="col-xs-8 text-center painel" id="conteudo">
              <h1 class="painel-content">
                LOGIN
              </h1>
            </div>
            <div class="row dnone" id="aviso">
              <div class="alert alert-warning alert-dismissible">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h4>
                  <i class="icon fa fa-warning"></i> Aviso!
                </h4>
                <p></p>
              </div>
            </div>
          </div>

        </section>

        <!-- Main content -->

      </div>
      <!-- /.content-wrapper -->
      <!-- Control Sidebar -->
      <!-- /.control-sidebar -->
      <!-- Add the sidebar's background. This div must be placed
                immediately after the control sidebar -->
    </div>


    <div class="login-box">
      <div class="login-logo">
        <a href="/">
          <p>
            <img src="images/logo.jpeg" width="140" height="100" />
        </a>
        </p>
      </div>
      <!-- /.login-logo -->
      <div class="login-box-body">
        <p class="login-box-msg">Iniciar sessão</p>

        <form role="form" name="dados" id="usuario" onsubmit="return false">
          <div class="form-group has-feedback">
            <input type="email" class="form-control" placeholder="Email" id="txt_email_cpf">
            <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
            <span class="help-block help-block-email_cpf">Este campo é obrigatório!</span>
          </div>
          <div class="form-group has-feedback">
            <input type="password" class="form-control" placeholder="Password" id="txt_senha">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
            <span class="help-block help-block-esqueci-senha">Este campo é obrigatório!</span>
          </div>
          <div class="row">
            <div class="col-xs-8">
              <div class="checkbox icheck">
                <label>
                                    <input type="checkbox" id="lembrarme"> Lembrar me
                                </label>
              </div>
            </div>
            <!-- /.col -->
            <div class="col-xs-8 form-group">
              <button type="submit" id="btn_validar" class="btn btn-primary btn-block btn-flat">Logar</button>
            </div>

            <div class="col-xs-8 form-group">
              <button type="button" id="btn_esqueci_senha" class="btn bg-purple marginbtn-esqueci-senha">Esqueci a senha</button>
            </div>

            <div class="col-xs-8 form-group">
              <button type="button" class="btn btn-block btn-success btn-cadastro">CADASTRO

                            </button>

            </div>

            <!-- /.col -->
          </div>
        </form>
        <!--
                <div class="social-auth-links text-center">
                    <p>- OR -</p>
                    <a href="#" class="btn btn-block btn-social btn-facebook btn-flat"><i class="fa fa-facebook"></i> Sign in using
                    Facebook</a>
                    <a href="#" class="btn btn-block btn-social btn-google btn-flat"><i class="fa fa-google-plus"></i> Sign in using
                    Google+</a>
                </div>
                <!- - /.social-auth-links -->

      </div>
      <!-- /.login-box-body -->
    </div>
    <!-- /.login-box -->



    <!-- Main Footer -->

    <footer class="main-footer">
      <!-- To the right -->
      <div class="pull-right hidden-xs">
        <a href="https://www.site.com.br" target="_blank"><img src="img/logo-min.jpg" height="30"></a>
      </div>
      <!-- Default to the left -->
      <span>Copyright &copy; 2018 <b> site</b>.</span> Todos os direitos reservados.
    </footer>


  <!--</div>-->
  <!-- /.container -->
  <!-- jQuery 2.2.3 -->
  <script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
  <!-- Bootstrap 3.3.6 -->
  <script src="bootstrap/js/bootstrap.min.js"></script>
  <!-- iCheck -->
  <script src="plugins/iCheck/icheck.min.js"></script>
  <script type="text/javascript" src="cordova.js"></script>
  <script type="text/javascript" src="scripts/platformOverrides.js"></script>
  <script type="text/javascript" src="js/scripts.js"></script>
  <script type="text/javascript" src="scripts/index.js"></script>


  <script>
    $(function() {
      $('input').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '20%' // optional
      });
    });
  </script>

</body>

</html>
    
asked by anonymous 27.01.2018 / 19:29

1 answer

0

First point, you are calling the wrong url in your ajax , there is no .cs after .svc

url: "../sistema/Bob.Servico/Usuario.svc/GetUsuario",

You need to point to a valid endpoint, by the address you assigned to url , it gives me the impression that you are trying to access an address beyond the root of your site, in another structure, and as if it were a static resource .

Your web service needs to be made available on a host as an application if it is not in the same environment as your site. If the service is hosted on another site, you need to point the full path to it:

url: "http://endereco_do_ws/Usuario.svc/GetUsuario",

Still, because it is a call to ajax, you still have to make the settings to enable the CORS request to have no problem with cross-dmain .

    
28.01.2018 / 15:41