J'ai créé un service Web REST que je dois utiliser dans une application asp.net. Le service est hébergé à partir d'une fenêtre de console. Je peux le faire fonctionner correctement, et je peux aussi en tirer des résultats lorsque je navigue dans un navigateur Web. Le problème est que, lorsque j'essaie d '"ajouter une référence de service" à partir de mon application asp.net, il se plaint de diverses choses selon l'URL du service que je pointe vers. Résultat final est je ne peux pas comprendre comment ajouter la référence de service.Impossible d'ajouter une référence de service au service WCF auto-hébergé
Mon interface est définie comme ceci:
[ServiceContract]
public interface IWave {
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/devices")]
List<Device> getDevices();
...
}
Voilà comment j'organise mon service:
// Port is 1178
var endPoint = new EndpointAddress(string.Format("http://localhost:{0}/wave", port));
var waveServiceSingleton = new WaveSVC();
binding = new WebHttpBinding();
var behavior = new WebHttpBehavior();
behavior.FaultExceptionEnabled = true;
host = new WebServiceHost(waveServiceSingleton, endPoint.Uri);
// Get the service debug behavior and tell it to include details about errors
ServiceDebugBehavior sdb;
sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
sdb.IncludeExceptionDetailInFaults = true;
host.AddServiceEndpoint(typeof(IWave), binding, "");
// Add mex endpoint
ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();
mexBehavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(mexBehavior);
host.AddServiceEndpoint(typeof(IWave), MetadataExchangeBindings.CreateMexHttpBinding(), endPoint.Uri.AbsoluteUri + "/mex");
host.Open();
Lorsque je navigue à http://localhost:1180/wave/devices, je vois une chaîne JSON dans le corps de mon navigateur. Ceci est attendu et fonctionne comme souhaité. Je ne peux pas pointer mon « Ajouter un service de référence » Assistant à cette URL, car il se plaint que:
The document at the url http://localhost:1178/wave/devices was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'XML Schema' is 'Data at the root level is invalid. Line 1, position 1.'.
- Report from 'DISCO Document' is 'Data at the root level is invalid. Line 1, position 1.'.
- Report from 'WSDL Document' is 'There is an error in XML document (1, 1).'.
- Data at the root level is invalid. Line 1, position 1.
Metadata contains a reference that cannot be resolved: 'http://localhost:1178/wave/devices'.
The remote server returned an unexpected response: (405) Method Not Allowed.
The remote server returned an error: (405) Method Not Allowed.
If the service is defined in the current solution, try building the solution and adding the service reference again.
je soupçonne lancinante que je dois signaler mon « Ajouter un service de référence » à la MEX, mais n » Je travaille soit et en effet, quand je navigue à l'adresse mex de http://localhost:1178/wave/mex, je reçois une page blanche.
EDIT 1
Juste pour éliminer JSON être le coupable, j'ai changé mon contrat à la sortie Xml au lieu de JSON. Le résultat était le même: je ne peux pas ajouter de référence de service en utilisant cette URL: http://localhost:1178/zwave/devices/xml (même si cette URL produit du XML).
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate= "/devices/xml")]
Merci d'avance pour toute aide fournie.
BTW - Avez-vous essayé d'utiliser svcutil au lieu de VS pour créer un proxy à partir des données mex? à partir de l'invite de commande VS: svcutil.exe /o:client.cs /config:app.config http: // localhost: 1178/wave/mex – Marijn