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>