IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Discussion :

Webservices - JSON - JQUERY


Sujet :

Services Web

  1. #1
    Membre du Club
    Inscrit en
    Septembre 2006
    Messages
    107
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Septembre 2006
    Messages : 107
    Points : 48
    Points
    48
    Par défaut Webservices - JSON - JQUERY
    Bonjour,

    Je n'arrive pas a consommer mon webservice avec JQUERY, message d'erreur générique : textStatus = error

    Voici le WS
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
        <WebMethod(True)> _
        Public Function DeleteSuiviFormation(ByVal idSuiviFormation As String) As String
            Dim jsSerializer As New System.Web.Script.Serialization.JavaScriptSerializer()
     
            Return jsSerializer.Serialize(DeleteEntity(idSuiviFormation))
        End Function
    Le JS :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    function WSDeleteSuiviFormation(suiviFormationToDelete){
        $.ajax({ url: getBaseURL()+"/WS/WSsuiviFormation.asmx/DeleteSuiviFormation",
            type: "POST",
            //contentType: "application/json; charset=utf-8",
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Content-type","application/json; charset=utf-8"); },
            data:'{idSuiviFormationList:"'+suiviFormationToDelete +'"}',
            dataType: "json",
            processData: false,
            error:function(XMLHttpRequest,textStatus,errorThrown) {ShowError(XMLHttpRequest,textStatus,errorThrown);}
        });
    }
    Le header :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Request URL:http://localhost:3065/SuiviFormation/WS/WSsuiviFormation.asmx/DeleteSuiviFormation
     
    Request Headers
    Accept:application/json, text/javascript, */*; q=0.01
    Content-Type:application/x-www-form-urlencoded, application/json; charset=UTF-8
    Origin:http://localhost:3065
    Referer:http://localhost:3065/SuiviFormation/Suivi.aspx
    User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3
    X-Requested-With:XMLHttpRequest
     
    Request Payload
    {idSuiviFormationList:"id"}

    J'ai mis un point d’arrêt dans le WS mais je ne passe mais pas dedans ...

    Merci de m'aider.

  2. #2
    Inactif  
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2007
    Messages
    6 604
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet NTIC

    Informations forums :
    Inscription : Janvier 2007
    Messages : 6 604
    Points : 13 314
    Points
    13 314
    Par défaut
    Bonjour

    As-tu testé unitairement ton webservice avant de constater que tu ne peux pas le consommer depuis ton client ?

  3. #3
    Membre du Club
    Inscrit en
    Septembre 2006
    Messages
    107
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Septembre 2006
    Messages : 107
    Points : 48
    Points
    48
    Par défaut
    Bon j'ai trouvé ce qu'il manquait, ce sont les attributs JSON au niveau du WebService :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <WebService(Namespace:="http://tempuri.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <System.ComponentModel.ToolboxItem(False)> _
    <ScriptService()> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class WSsuiviFormation
        Inherits System.Web.Services.WebService
     
        <WebMethod()> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
        Public Function HelloWorld() As String
            Return "Hello World"
        End Function
    et au niveau client j'ai ca :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    function HelloWorld(){
        $.ajax({ url: '/SuiviFormation/WS/WSsuiviFormation.asmx/HelloWorld',
            type: "POST",
            contentType: "application/json; charset=utf-8",
            data: '{}',
            dataType: "json",
            processData: false,
            success: function(data) {MAJSuccess(data);},
            error:function(XMLHttpRequest,textStatus,errorThrown) {MAJError(XMLHttpRequest,textStatus,errorThrown);}
        });
    }

  4. #4
    Membre du Club
    Inscrit en
    Septembre 2006
    Messages
    107
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Septembre 2006
    Messages : 107
    Points : 48
    Points
    48
    Par défaut
    Pour expliquer pourquoi ce poste n'est pas en résolu, l'appel du WS sans paramètre fonctionne correctement mais impossible de faire passer un paramètre en JSON.

Discussions similaires

  1. [EJB / REST / JSON / JQuery] Problème pour faire un POST
    Par saveriu dans le forum Services Web
    Réponses: 1
    Dernier message: 19/04/2012, 11h08
  2. webService JSON : problème lors de l'appel depuis un autre site
    Par Pat_AfterMoon dans le forum Services Web
    Réponses: 1
    Dernier message: 22/11/2011, 01h22
  3. Struts 2 + JSON + JQuery
    Par bourbah dans le forum Struts 2
    Réponses: 2
    Dernier message: 15/11/2011, 11h49
  4. Appel WebService grâce à JQuery
    Par H1B4K dans le forum ASP.NET
    Réponses: 0
    Dernier message: 30/03/2011, 17h36
  5. WebService JSON retourne du XML
    Par d1g-2-d1g dans le forum Services Web
    Réponses: 5
    Dernier message: 14/11/2009, 00h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo