我有一个 WCF 休息网络服务。它工作正常。我想了解端点元素中可用的不同配置值。
特别是,我试图了解地址元素的用途。更改值似乎并没有改变我处理服务的方式。为此,我从 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";
}
}