私はasp.netアプリケーション内から消費する必要があるREST Webサービスを作成しました。サービスはコンソールウィンドウからホストされます。私はそれをうまく走らせることができ、ウェブブラウザでサーフィンしても出力を得ることができます。問題は、私がasp.netアプリケーションから "Add Service Reference"をしようとすると、それが指しているサービスURLに応じてさまざまなことが起こるということです。最終的には、サービス参照を追加する方法がわかりません。サービス参照を自己ホスト型WCFサービスに追加できません
私のインターフェイスはそうのように定義されています。
[ServiceContract]
public interface IWave {
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/devices")]
List<Device> getDevices();
...
}
は、ここで私は私のホスティングサービスだ方法は次のとおりです。
// 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();
私はhttp://localhost:1180/wave/devicesを参照すると、私は私の身体にJSON文字列を参照してくださいブラウザ。これは期待どおりで、必要に応じて動作します。それはそれを文句を言うように私は、このURLに私の「サービス参照の追加」ウィザードを指すことはできません。
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.
私は私が私のMEXに「サービス参照の追加」ポイントする必要があることをしつこい疑いを持っているが、それは」doesnの私がhttp://localhost:1178/wave/mexのmexアドレスを参照すると、空白のページが表示されます。ただ、犯人であることJSONを排除する
EDIT 1
、私の代わりに、JSONの出力XMLに私の契約を変更しました。結果は同じでした:このURLを使用してサービス参照を追加することはできません:http://localhost:1178/zwave/devices/xml(そのURLはXMLを生成します)。
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate= "/devices/xml")]
ご協力いただきありがとうございます。
ところで私のために働いた
で
を交換してください - あなたが作成する代わりに、VSのsvcutilを使用してみましたがmexデータからのプロキシ? VSコマンドプロンプトから:svcutil.exe /o:client.cs/config:app.config http:// localhost:1178/wave/mex – Marijn