我在控制台应用程序中托管了一个WCF数据服务。它运行没有抱怨,当安全设置为"无"它就像一个魅力。 现在,当我启用传输安全性时,它仍会运行,但是当我在Web浏览器中点击URL时它找不到它。我使用自签名证书进行测试。
我将不胜感激任何帮助和建议。
提前谢谢。
这是我的app.config:
<configuration>
<system.web>
<compilation debug="true" />
</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>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
</handlers>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="TransportSecurity" >
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
<!--<security mode="None"/>-->
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="ConsoleServiceHost.BooksDataService">
<host>
<baseAddresses>
<add baseAddress="https://localhost:8900" />
</baseAddresses>
</host>
<endpoint address="BooksDataService" binding="webHttpBinding" bindingConfiguration="TransportSecurity" behaviorConfiguration="webHttpBehavior" contract="System.Data.Services.IRequestHandler"></endpoint>
<!--<endpoint address="mex" binding="mexHttpsBinding" name="mex" contract="IMetadataExchange" />-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SSLBehave">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<serviceCertificate findValue="a3 6f 22 85 86 09 f0 4b 12 3c ea 18 10 c7 14 63 32 f8 a0 6e" storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" />
</serviceCredentials>
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="https" port="443"/>
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Wrapped"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
...
</configuration>
这是我的服务代码:
public class BooksDataService : DataService<SampleDbEntities>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
以下是托管它的代码:
static void Main()
{
var host = new DataServiceHost(typeof(BooksDataService), new Uri[0]);
host.Open();
Console.WriteLine(host.BaseAddresses[0]);
Console.ReadKey();
host.Close();
}
答案 0 :(得分:0)
解决。我没有将证书附加到应用程序端口。我错过了这个命令:
netsh http add sslcert ipport=0.0.0.0:8900 appid={cc57b9c6bbd7-468d-81be-779e6a74099e} certhash=a36f22858609f04b123cea1810c7146332f8a06e
感谢Hasan Baidoon回答的这篇帖子: WCF DataService over Https
感谢您CodeCaster的合作。