Console hosted WCF data service with transport security running but not found by clients
我有一个自托管在控制台应用程序中的 WCF 数据服务。它运行时没有抱怨,当安全设置为"无"时,它就像一个魅力。
现在,当我启用传输安全性时,它仍然运行,但是当我在网络浏览器中点击 url 时,它找不到它。我正在使用自签名证书对其进行测试。
我将不胜感激任何帮助和建议。
提前谢谢你。
这是我的 app.config:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | <configuration> <system.web> <compilation debug="true" /> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> </modules> <handlers> </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> </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> </defaultPorts> </useRequestHeadersForMetadataAddress> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="webHttpBehavior"> <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Wrapped"/> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel> ... </configuration> |
这是我的服务代码:
1 2 3 4 5 6 7 8 9 | public class BooksDataService : DataService<SampleDbEntities> { public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("*", EntitySetRights.All); config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; } } |
这是托管它的代码:
1 2 3 4 5 6 7 8 9 10 11 |
解决了。我没有将证书附加到应用程序端口。我错过了这个命令:
1 | netsh http add sslcert ipport=0.0.0.0:8900 appid={cc57b9c6bbd7-468d-81be-779e6a74099e} certhash=a36f22858609f04b123cea1810c7146332f8a06e |
感谢 Hasan Baidoon 回答的这篇文章:
Https 上的 WCF 数据服务。
感谢 CodeCaster 的合作。