2011-01-14 10 views
0

私はWCF休憩Webサービスを持っています。それは正常に動作しています。私は、エンドポイント要素内で利用可能なさまざまな設定値を理解したいと思っています。システムの説明.servicemodel endpoint.address要素rest service

特に、私はアドレス要素の目的を理解しようとしています。値を変更しても、サービスにどのように対処できるかは変わっていないようです。このために、私はVisual Studio 2010とcassiniからサービスを実行しています。ポート番号は888に設定されています。

アドレスが空文字列に設定されています。 http://localhost:888/restDataService.svc/helloは「hello world」を返します。

アドレスが「localhost」に設定されています。 http://localhost:888/restDataService.svc/helloは「hello world」を返します。

アドレスが "pox"に設定されています。 http://localhost:888/restDataService.svc/helloは「hello world」を返します。

アドレス欄にどのような値を設定しても問題ありません。それはURLに影響しません。私が持っている私の唯一の説明は、値が非RESTサービスの方が多いということです。

<system.serviceModel> 
    <services> 
    <service behaviorConfiguration="MobileService2.DataServiceBehaviour" name="MobileService2.DataService"> 

     <endpoint address="pox" binding="webHttpBinding" contract="MobileService2.IRestDataService" behaviorConfiguration="webHttp"> 
     </endpoint> 

     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
    </services> 
    <behaviors> 
    <endpointBehaviors> 
     <behavior name="webHttp"> 
     <webHttp /> 
     </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
     <behavior name="MobileService2.DataServiceBehaviour" > 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
</system.serviceModel> 

私も

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class RestDataService : IRestDataService 
{ 
    public string Hello() 
    { 
     return "hello"; 
    } 
} 

答えて

2

次のサービス契約

[ServiceContract] 
    public interface IRestDataService 
    { 
     [OperationContract] 
     [WebGet(UriTemplate = "hello")] 
     string Hello(); 
    } 

そして.SVCで

<%@ ServiceHost Language="C#" Debug="true" 
      Service="MobileService2.RestDataService" 
      Factory="System.ServiceModel.Activation.WebServiceHostFactory" 
      CodeBehind="RestDataService.svc.cs" %> 

そして 'コードビハインド' を持つことができます。また、あなたの設定のサービス要素を表示しますか? 2回目と3回目のテストでHTTP 404リソースが見つからないため、設定が使用されていないか、アプリケーションの他のインスタンスにアクセスしていると思われます(ポート80を使用するようにCassiniを構成しましたか?あなたのテストのための

正しいアドレスは次のとおりです:service要素で、あなたの名前が(を含む正確サービスタイプの名前と同じであることを

  1. http://localhost/restDataService.svc/hello
  2. http://localhost/restDataService.svc/localhost/hello
  3. http://localhost/restDataService.svc/pox/hello

チェック.svcマークアップのServiceHostディレクティブで使用される名前空間(namespace)。

+0

+1絶対に正しい!ちょうどこれを自分でテストしました。設定が正しい場合、これが発生します。 –