HTTP GetでWCFサービスの使用方法(Visual Studio 2010内)
-
28-09-2019 - |
質問
HTTP Getを使用して非常にシンプルなWCFサービスを使用しようとしましたが、機能することはできません。私たちはそれらの「ガイド」に従っていますが、それは機能しません
- 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サービスアプリケーション」プロジェクトを作成します
iServiceインターフェイスをこのコードに置き換えます
[ServiceContract()] public interface IService1 { [OperationContract()] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetData/{value}")] string GetData(string value); }
サービスクラスをこのコードに置き換えます
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メソッドを呼び出してみてください
誰かがこれまたは似たような機能を取得した場合、作業例に関する情報を返信できればとても親切です。
どうもありがとうございます
解決
私はあなたのサンプルを再現しました - 魅力のように機能します。
1つのポイント:サービス契約(public interface IService1
)およびサービスの実装(public class Service1 : IService1
).NETネームスペース内に存在しますか?
もしそうなら、あなたはあなたの *.svcとあなたの web.config
含める:
<services>
<service name="Namespace.Service1">
<endpoint address="" binding="webHttpBinding"
contract="Namespace.IService1"
behaviorConfiguration="WebBehavior1">
</endpoint>
</service>
</services>
<service name="...">
属性と <endpoint contract="...">
これを機能させるには、.NET名前空間を含める必要があります。
所属していません StackOverflow