我有一個WCF休息webservice。它工作正常。我想了解端點元素中可用的不同配置值。解釋system.servicemodel爲休息服務的endpoint.address元素
特別是,我想了解地址元素的用途。改變價值似乎並沒有改變我如何處理這項服務。爲此,我正在運行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」。
無論我在地址欄中設置了什麼值。它不會影響網址。我唯一的解釋是價值更多的是非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";
}
}
+1絕對正確!我自己測試過這個 - 當配置正確時,這是發生的行爲。 – 2011-01-14 18:10:16