【发布时间】:2011-09-24 06:42:23
【问题描述】:
首先,网上有很多关于这方面的文章,但其中大部分是针对 WCF 3.5 的。我正在使用 WCF 4.0 的一些特性,这使得场景有点不同。
以下是我的合同:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate="x?v={value}")]
string GetData(int value);
}
以下是我的服务类:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
以下是我的 web.config
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
</handlers>
</system.webServer>
我没有使用任何 svc 文件,所以在 Global.asax 中我编写了以下代码行来在路径“blah”处公开我的服务
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("blah", new WebServiceHostFactory(), typeof(Service1)));
}
如果我在 web.config 中更改标准端点,现在可以启用基本身份验证,如下所示:
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint automaticFormatSelectionEnabled="true">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
我收到以下错误:
找不到一个基地址 匹配端点的方案 https 与绑定 WebHttpBinding。 注册的基地址方案是 [http]。
从现在开始我应该怎么做才能让它发挥作用?我将在哪里检查每个请求提供的用户名/密码?
【问题讨论】:
标签: wcf wcf-security wcf-rest