我已经能够为集成项目创建一个很好的WCF服务,它可以返回纯xml,json和soap的结果。这很好用,直到我开始实现安全性。使用适用于以下内容的WebHttpBindings时,绕过了wcf服务中内置的ws安全功能:
<webHttp defaultOutgoingResponseFormat="Json"/>
和
[OperationContract()]
[WebGet(UriTemplate = "GetSomething/{someID}/{anotherID}?somethingElse={somethingElse}")]
SomeResponse GetSomething(string someID,string anotherID, DateTime somethingElse)
我喜欢玩我的第一个安静的api,但是我需要完成一个项目,并且要求包括一个安全的身份验证策略。我不需要将结果作为json返回,也不一定是休息服务,但这引起了我的好奇心。
......有关身份验证策略/ WCF REST服务的任何好主意吗?
答案 0 :(得分:0)
您可能需要clientCredentialType =“Certificate”或“Windows”
<webHttpBinding>
<binding name ="RestSSL">
<security mode ="Transport">
<transport clientCredentialType= "Windows" />
</security>
</binding>
</webHttpBinding>
如果您使用证书,您还需要将serviceBehavior的certificateValidationMode设置为类似PeerTrust,ChainTrust等。http://msdn.microsoft.com/en-us/library/system.servicemodel.security.x509certificatevalidationmode.aspx
<behaviors>
<serviceBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="1048576"/>
<serviceMetadata httpGetEnabled="False" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
<serviceCredentials>
<!-- Please note: the app pool will need an identity with access to this cert-->
<serviceCertificate findValue="myCertSubject.myDomain.com"
storeLocation="LocalMachine"
storeName="My"
x509FindType="FindBySubjectName"/>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
答案 1 :(得分:0)
一般来说,大多数人在确保安全的wcf服务时都会使用OAuth。 OAuth是一种开放协议,允许通过桌面和Web应用程序的简单标准方法进行安全的API身份验证。它允许客户端提供一个消费者密钥,用于标识必须为每个服务调用发送的客户端。该信息作为HTTP Authorization标头的一部分发送。从here
下载OAuth类有关实施细节,请查看此Code Project Article