Bonjour chers membres,j'ai un problème lorsque j'utilise les Methode des Mise à jour (PUT,POST,DELETE) il me renvoi "Methode non autorisée".
Je précise que je n'utilise pas WCF Data Services(OData) mais j'ai juste ajouter des Attributs (WebGet et WebInvoke)
Fichier de Configuration
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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.Web.Services; namespace WcfAndroid { [ServiceContract] public interface IService1 { [OperationContract] [WebGet(UriTemplate="ServiceAndroid/nom={nom}/pnom={pnom}",RequestFormat=WebMessageFormat.Xml,ResponseFormat=WebMessageFormat.Xml,BodyStyle=WebMessageBodyStyle.Bare)] string GetData(String nom,String pnom); [OperationContract] [WebInvoke(UriTemplate = "ServiceAndroid/add?nom={nom}&pnom={pnom}",Method="POST",RequestFormat=WebMessageFormat.Xml,ResponseFormat=WebMessageFormat.Xml,BodyStyle=WebMessageBodyStyle.Bare)] void Add(String nom, String pnom); // TODO: ajoutez vos opérations de service ici } // Utilisez un contrat de données comme indiqué dans l'exemple ci-après pour ajouter les types composites aux opérations de service. [DataContract] public class CompositeType { bool boolValue = true; string stringValue = "Hello "; [DataMember] public bool BoolValue { get { return boolValue; } set { boolValue = value; } } [DataMember] public string StringValue { get { return stringValue; } set { stringValue = value; } } } } ////////////////////////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using WcfAndroid.DAO; namespace WcfAndroid { // REMARQUE*: vous pouvez utiliser la commande Renommer du menu Refactoriser pour changer le nom de classe "Service1" dans le code, le fichier svc et le fichier de configuration. // REMARQUE*: pour lancer le client test WCF afin de tester ce service, sélectionnez Service1.svc ou Service1.svc.cs dans l'Explorateur de solutions et démarrez le débogage. public class Service1 : IService1 { AndroidBDEntities db = new AndroidBDEntities(); public string GetData(string nom, string pnom) { try { Client client = new Client() { Nom = nom, Prenom = pnom }; db.Client.Add(client); db.SaveChanges(); } catch (Exception e) { return e.Message; } return String.Format("Votre nom est:{0} {1}", nom, pnom); } public void Add(string nom, string pnom) { try { Client client = new Client() { Nom = nom, Prenom = pnom }; db.Client.Add(client); db.SaveChanges(); WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK; //WebOperationContext.Current.OutgoingResponse.SetStatusAsCreated(new Uri("http://localhost:8657/Service1.svc/ServiceAndroid/add?nom="+nom+"&pnom="+pnom+"")); } catch (Exception e) { } } } } //////////////////////////////////////////////////////////////////////////////////////
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.5"><assemblies><add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /></assemblies></compilation> <httpRuntime targetFramework="4.5" /> </system.web> <system.serviceModel> <services> <service name="WcfAndroid.Service1"> <endpoint address="" behaviorConfiguration="svc" binding="webHttpBinding" contract="WcfAndroid.IService1" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="svc"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="serviceMeta"> </behavior> </serviceBehaviors> </behaviors> <protocolMapping> <add binding="basicHttpsBinding" scheme="https" /> </protocolMapping> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <!-- Pour parcourir le répertoire racine de l'application Web lors du débogage, définissez la valeur ci-dessous sur true. Définissez-la sur false avant le déploiement pour ne pas divulguer d'informations du dossier de l'application Web. --> <directoryBrowse enabled="true" /> </system.webServer> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> <connectionStrings><add name="AndroidBDEntities" connectionString="metadata=res://*/DAO.Model1.csdl|res://*/DAO.Model1.ssdl|res://*/DAO.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=AndroidBD;persist security info=True;user id=userandroid;password=android;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings></configuration>
Partager