Bonjour,
J'ai un service qui devrait avoir la possibilité d'etre consommé soit en SOAP soit en REST. Mon probleme c'est que le REST ne renvoie rien.
Mon code:
Interface
Facade (implementation dê l'interface)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 [ServiceContract] public interface IClients { [OperationContract] [WebGet(UriTemplate = "clients/{clientId}", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)] string[] GetAllClientsByClientId(int clientId); }
Web.config
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 [AspNetCompatibilityRequirements (RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)] public partial class ExposedService : IClients { public string[] GetAllClientsByClientId(int clientId) { string[] clientArray = null; try { List<Entity.Clients> clients = BusinessLogicLayer.Clients.GetAllClientsByClientId(clientId, out errMessage); if (clients.Count > 0) { clientArray = new string[clients.Count]; for (int i = 0; i < clients.Count; i++) { clientArray[i] = clients[i].ClientName; } } else { clientArray = new string[0]; } } catch (Exception ex) { WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.BadRequest; errMessage = "GetAllClientByClientId failed, error : " + ex.Message; Tools.Log.MonitoringLogger.Debug(errMessage); } return clientArray; } } }
Avez-vous une suggestion ?
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 <system.serviceModel> <services> <service name="WCFServiceFacade.ExposedService" behaviorConfiguration="WCFWebServices.Behavior"> <endpoint address="http://localhost:10880/Services.svc" binding="basicHttpBinding" contract="WCFInterface.IClients"/><!--SOAP--> <endpoint address="rest" binding="webHttpBinding" contract="WCFInterface.IClients"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="WCFWebServices.Behavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="restBehavior"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel>
Merci
Partager