今天是个好日子...
显然,我没有为我的WCF服务正确设置模拟.我不希望逐个方法地设置安全性(在实际的代码隐藏中).该服务(目前)是开放的,由内联网上的每个人调用.
所以我的问题是......
问:我错过了哪些web-config标签?
问:我需要在web-config中进行哪些更改才能进行模拟工作?
服务Web.config看起来像......
<configuration>
<system.web>
<authorization>
<allow users="?"/>
</authorization>
<authentication mode="Windows"/>
<identity impersonate="true" userName="MyDomain\MyUser" password="MyPassword"/>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="wcfFISH.DataServiceBehavior" name="wcfFISH.DataService">
<endpoint address="" binding="wsHttpBinding" contract="wcfFISH.IFishData">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="wcfFISH.DataServiceBehavior">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
如果您总是想冒充客户端,对于所有操作,则将以下内容添加到<behavior>元素中,即在<serviceMetadata>元素之后:
<serviceAuthorization impersonateCallerForAllOperations="true" />
Run Code Online (Sandbox Code Playgroud)
如果您尝试在应用程序级别进行模拟,那么您通常无法在WCF中执行此操作,因为WCF实际上不是ASP.NET管道的一部分.
最简单的解决方法是将WCF应用程序放在自己的应用程序池中,并将池的进程标识设置为您要模拟的用户.
另一种方法是打开ASP.NET兼容模式,将其添加到<system.servicemodel>:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
Run Code Online (Sandbox Code Playgroud)
您有时也需要使用以下内容装饰您的服务:
[AspNetCompatibilityRequirements(
RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
Run Code Online (Sandbox Code Playgroud)
但请记住,这将限制您利用许多其他较新的WCF功能(如MSMQ或TCP绑定)的能力.我更喜欢隔离的应用程序池方法.
| 归档时间: |
|
| 查看次数: |
6257 次 |
| 最近记录: |