私はWCFレストWebサービスを持っています。正常に動作しています。endpoint 要素内で使用できるさまざまな構成値を理解したいと考えています。
特に、住所要素の目的を理解しようとしています。値を変更しても、サービスへの対処方法は変わらないようです。このために、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>
また、次のサービス契約を結んでいます
[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" %>
そして「分離コード」
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class RestDataService : IRestDataService
{
public string Hello()
{
return "hello";
}
}