使用自定义 UserNamePasswordValidator 的 WCF 数据服务
我正在尝试设置 WCF 数据服务来使用我的自定义 UserNamePasswordValidator
它非常适合标准 WCF 服务;我遇到的问题是这样的:在我的 web.config 中,我无法指定 WCF 数据服务端点,因为它没有实现我可以使用的合同。见下文
<service behaviorConfiguration="GetHttpsIncludeFaults" name="WCFDataService">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHTTP"
Contract="WHAT-GOES-HERE?"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<behavior name="GetHttpsIncludeFaults">
<dataContractSerializer maxItemsInObjectGraph="204800" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="pjt.UPValidate, pjt"/>
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
对于我的普通 WCF 服务,我只需指定该类实现的接口;对于数据服务,我没有这样的接口。
如果有更好的方法来自定义 ServiceBehavior
我愿意接受,这只是我知道如何做到这一点的唯一方法。
I am trying to setup a WCF Data Service to use my custom UserNamePasswordValidator
it is working great for standard WCF Services; the problem I have is this: In my web.config I cannot specify the WCF Data Service endpoint because it does not implement a contract I can use. See below
<service behaviorConfiguration="GetHttpsIncludeFaults" name="WCFDataService">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHTTP"
Contract="WHAT-GOES-HERE?"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<behavior name="GetHttpsIncludeFaults">
<dataContractSerializer maxItemsInObjectGraph="204800" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="pjt.UPValidate, pjt"/>
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
For my normal WCF services, I simply sepcify the interface that the class implements; with Data Services I have no such interface.
If there is a better way to customize the ServiceBehavior
I'm open to that, this is just the only way I know how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一番研究后,我通过使用此合约得到了一个新错误:
System.Data.Services.IRequestHandler
。在克服了我的服务未实现合约的错误之后,WCF 数据服务似乎只能与 webHttpBinding 配合使用——它不支持 TransportWithmessageCredential 安全性。
所以,这并不能完全回答我的问题;但是,这似乎是通过自定义用户名/密码验证器保护 WCF 数据服务的唯一方法:http://blogs.msdn.com/b/astoriateam/archive/2010/07/21/odata-and-authentication-part-6-custom-basic-authentication.aspx
涉及使用 BASIC 身份验证,并编写您自己的 HttpModule 以使 IIS 将身份验证委托给您自己的自定义用户名密码验证器。显然,这只能通过 HTTPS 使用。
After a bit of poking around, I was able to get a new error by using this contract:
System.Data.Services.IRequestHandler
.After getting past the error that the contract was not implemented by my service, it seems as if WCF Data Services only work with webHttpBinding -- which does not support TransportWithmessageCredential security.
So, this doesn't exactly answer my question; however, this appears to be the only way to secure a WCF Data Service via a custom username / password validator: http://blogs.msdn.com/b/astoriateam/archive/2010/07/21/odata-and-authentication-part-6-custom-basic-authentication.aspx
It involves using BASIC authentication, and writing your own HttpModule to have IIS delegate the authentication to your own custom username password validator. Obviously, this should only be used over HTTPS.