非常に単純なWCFサービスをHTTp Getで使用しようとしましたが、動作させることはできません。 私たちは、これらの「ガイド」に続いてきたが、それは動作しませんHTTPでWCFサービスを使用する方法(Visual Studio 2010内)
- http://msdn.microsoft.com/en-us/library/bb412178.aspx
- http://www.dotnetfunda.com/articles/article779-simple-5-steps-to-expose-wcf-services-using-rest-style-.aspx
私たちは、次のURLを使用して当社のサービスを呼び出すと、我々はページが見つからないというエラーが出ます:
ベースURL(のhttp:// localhostを:9999/Service1.svc)が正常に動作し、正しくWCFサービス情報ページを返します。
これは、例を再現するための手順とコードです。
- のVisual Studio 2010では、新しい "WCFサービスアプリケーション" プロジェクト
このコード
[ServiceContract()] public interface IService1 { [OperationContract()] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetData/{value}")] string GetData(string value); }
でこのコード
でサービスクラスを交換IServiceインターフェイスを置き換えを作成public class Service1 : IService1 { public string GetData(string value) { return string.Format("You entered: {0}", value); } }
web.configはこのようになります
<system.web> <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <services> <service name="Service1"> <endpoint address="" binding="webHttpBinding" contract="IService1" behaviorConfiguration="WebBehavior1"> </endpoint> </service> </services> <behaviors> <endpointBehaviors> <behavior name="WebBehavior1"> <webHttp helpEnabled="True"/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors>
- を押してファイル名を指定して実行し、誰かがこのまたは似たような作業を得る場合は、できれば、それはとても親切だろうGetメソッド
呼び出そう実際の例に関する情報を返信してください。魔法のように動作します -
は、私はあなたのサンプルを再作成し、非常に
あなたは非常に正しいです...それは、欠落しているルート名前空間のためだけでした。他のバインディングではうまく動作しますが(ルート名前空間なし)、webHttpBindingではうまく動作しません。どうもありがとうございました。 –