在IIS上設置「需要SSL」選項意味着您正在使用客戶端證書執行身份驗證。如果您沒有任何客戶端證書身份驗證,只需將該選項設置爲忽略或禁用該選項即可。
爲了避免您的服務僅在HTTPS上投放,請從您網站上的「綁定」選項中移除HTTP綁定。否則,只需公開您的綁定以將傳輸用作安全機制,並且應該只處理僅在HTTPS上提供服務的WCF服務。
UPDATE:
請找我如何有IIS上承載的RESTful服務以https:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class RestService
{
// TODO: Implement the collection resource that will contain the SampleItem instances
private static List<SampleItem> sampleCollection = new List<SampleItem>();
[WebGet(UriTemplate = "/get-Collection")]
public List<SampleItem> GetCollection()
{
// TODO: Replace the current implementation to return a collection of SampleItem instances
if (sampleCollection.Count == 0)
{
sampleCollection = new List<SampleItem>();
sampleCollection.Add(new SampleItem() { Id = 1, StringValue = "Hello 1" });
sampleCollection.Add(new SampleItem() { Id = 2, StringValue = "Hello 2" });
sampleCollection.Add(new SampleItem() { Id = 3, StringValue = "Hello 3" });
sampleCollection.Add(new SampleItem() { Id = 4, StringValue = "Hello 4" });
sampleCollection.Add(new SampleItem() { Id = 5, StringValue = "Hello 5" });
}
return sampleCollection;
}
}
我的Global.asax:
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private void RegisterRoutes()
{
// Edit the base address of Service1 by replacing the "Service1" string below
RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(RestService)));
}
}
我的web.config文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<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>
</system.webServer>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logKnownPii="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
<endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true" />
</diagnostics>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxBufferSize="500000" maxReceivedMessageSize="500000">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceCredentials>
<serviceCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="localhost" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
現在我的IIS有HTTPS綁定指定:
現在我的虛擬目錄已配置名稱XmlRestService,因此當我瀏覽到資源我得到下面的輸出:
您是如何訪問該服務的?從瀏覽器或wcf代理? – BNL 2012-02-06 16:49:58
綁定/端點配置對於您的svc是什麼樣的? – 2012-02-06 16:50:22
初始嘗試訪問正在通過瀏覽器完成。我已經添加了端點配置。 – Bullines 2012-02-06 17:33:23