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

AJAX Discussion :

WebService SVC / site web : Erreur 415 "application/json; charset=utf-8"


Sujet :

AJAX

  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    66
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Avril 2011
    Messages : 66
    Par défaut WebService SVC / site web : Erreur 415 "application/json; charset=utf-8"
    Bonjour à tous,

    je développe un nouveau site web chez moi, ce site est censé appeler un webservice.
    Jusque là, rien de bien fantastique !

    Mon webservice est accessible en local chez moi à l'adresse http://localhost:51819/Service2.svc (j'ai accès au
    également au wsdl)

    Mon site web est accessible au même moment à l'adresse http://localhost:51819/EspacePerso

    Seulement quand j'essai d'accéder à une des méthodes du webservice j'ai le message suivant qui est déclenché :
    "Service call failed: 415 | Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'".
    Je n'arrive pas à trouver d'où peut venir le problème.

    Merci d'avance à ceux qui prendront le temps de jeter un oeil à mon problème.

    Voici mon javascript d'appel de mon webService
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    function deleteExercice(idExercice) {
        try {
            varType = "POST";
            varUrl = "deleteExercice";
            varData = '{"idExercice": "' + idExercice + '"}';
            varContentType = "application/json; charset=utf-8";
            varProcessData = true;
            CallService();
        }
        catch (e)
        { alert(e.message); }
    }
     
    function CallService(/*funct*/) {
        $.ajax({
            type: varType,  //GET or POST or PUT or DELETE verb
            url: 'http://localhost:51819/Service2.svc/' + varUrl,    // Location of the service
            data: varData,  //Data sent to server
            contentType: varContentType,    // content type sent to server
            //dataType: varDataType,          //Expected data format from server
            processdata: varProcessData,    //True or False
            success: function (msg) {
                alert('ok');//if (funct) funct(msg.d);
            },
            error: ServiceFailed// When Service call fails
        });
    }
     
    function ServiceFailed(result) {
        alert('Service call failed: ' + result.status + ' | ' + result.statusText);
        Type = null;
        varUrl = null;
        Data = null;
        ContentType = null;
        DataType = null;
        ProcessData = null;
    }
    Mon svc :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <%@ ServiceHost Language="C#" Debug="true" Service="Service2" CodeBehind="~/App_Code/Service2.cs"%>
    Ma classe Service2.cs
    Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    using System;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
     
    [ServiceContract]
    public class Service2
    {
    	[OperationContract]
    	public void DoWork()
    	{
    		// Add your operation implementation here
    		return;
    	}
     
    	// Add more operations here and mark them with [OperationContract]
     
        [OperationContract]
        public void deleteExercice(string idExercice)
        {
            BXSportManager.GestionExercices.SupprimerExercice(int.Parse(idExercice));
        }
    }

    Et enfin mon web.config
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.5">
          <assemblies>
            <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          </assemblies>
        </compilation>
        <httpRuntime targetFramework="4.5"/>
      </system.web>
      <connectionStrings>
        <add name="StarterSite" connectionString="Data Source=|DataDirectory|\BXSportDB.sdf" providerName="System.Data.SqlServerCe.4.0"/>
        <add name="Entities" connectionString="metadata=res://*/Bdd.csdl|res://*/Bdd.ssdl|res://*/Bdd.msl;provider=System.Data.SqlServerCe.4.0;provider connection string='Data Source=&quot;BXSport\App_Data\BXSportDB.sdf&quot;'" providerName="System.Data.EntityClient"/>
      </connectionStrings>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246"/>
            <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246"/>
            <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <system.data>
        <DbProviderFactories>
          <remove invariant="System.Data.SqlServerCe.4.0"/>
          <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
        </DbProviderFactories>
      </system.data>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
          multipleSiteBindingsEnabled="true" />
        <services>
          <service name="Service2">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttp" contract="Service2" />
            <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="basicHttp" allowCookies="true"
                     maxReceivedMessageSize="200000000"
                     maxBufferSize="200000000"
                     maxBufferPoolSize="200000000"
                     >
              <readerQuotas maxDepth="32"
                   maxArrayLength="2000000000"
                   maxStringContentLength="2000000000"/>
            </binding>
          </basicHttpBinding>
          <customBinding>
            <binding name="Service2.customBinding0">
              <binaryMessageEncoding />
              <httpTransport />
            </binding>
          </customBinding>
        </bindings>
        <client/>
      </system.serviceModel>
    </configuration>

  2. #2
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 198
    Par défaut
    Bonjour,
    la réponse me semble être dans le message d'erreur
    type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'".

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    66
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Avril 2011
    Messages : 66
    Par défaut
    Bonjour,

    Comment donc faire pour que ce soit donc le type 'application/json; charset=utf-8' qui soit attendu ?

Discussions similaires

  1. Réponses: 1
    Dernier message: 02/10/2007, 11h06
  2. Intégrer une application VB6 dans un site web possible ?
    Par totofe7613 dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 21/03/2007, 16h04
  3. Erreur d'évaluation (parse) dans le fichier web.xml de l'application
    Par popinenhbourg dans le forum Servlets/JSP
    Réponses: 9
    Dernier message: 15/05/2006, 15h38
  4. Site web en JSP couplé à une application Offline
    Par semyazas dans le forum Servlets/JSP
    Réponses: 3
    Dernier message: 21/04/2006, 09h05
  5. Réponses: 2
    Dernier message: 08/11/2003, 23h42

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