我有一個簡單的WCF服務,它使用WSHttpBinding和Windows身份驗證。我試圖強制服務器在每次調用此服務的方法時模擬客戶端的身份。通過配置WCF模擬
我嘗試了WCF Service Impersonation給出的建議,但我並沒有得到滿意的結果。當我嘗試導航到WCF服務的着陸頁,我看到的錯誤:
The contract operation 'GetAdvice' requires Windows identity for automatic impersonation. A Windows identity that represents the caller is not provided by binding ('WSHttpBinding',' http://tempuri.org/ ') for contract ('IMagicEightBallService',' http://tempuri.org/ '.
上任何想法此錯誤的想告訴我?
整個解決方案可以在ftp://petio.org/2011/07/01/MagicEightBall/(或在http://petio.org/2011/07/01/MagicEightBall.zip下載)瀏覽。我只是將該項目發佈到本地IIS文件夾並在http://localhost/MagicEightBall/MagicEightBallService.svc上訪問該服務。
謝謝!
UPDATE:
我服務的Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Petio.MagicEightBall.MagicEightBallService" behaviorConfiguration="MagicEightBallServiceBehavior">
<endpoint name="WSHttpBinding_WindowsSecurity_IMagicEightBallService"
address="http://localhost/MagicEightBall/MagicEightBallService.svc"
binding="wsHttpBinding"
contract="Petio.MagicEightBall.IMagicEightBallService" />
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MagicEightBallServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceAuthorization impersonateCallerForAllOperations="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我的服務代碼:
public class MagicEightBallService : IMagicEightBallService
{
[OperationBehavior(Impersonation=ImpersonationOption.Required)]
public string GetAdvice()
{
MagicEightBall ball = new MagicEightBall();
return ball.GetAdvice();
}
}
謝謝,我只需要模擬配置選項的正確組合。 –
對於未來的其他人:如果您使用,那麼您必須確保使用[OperationBehavior(...)]裝飾所有服務的方法。這對我造成了很多困惑,因爲我錯誤地認爲impersonateCallerForAllOperations會自動爲我執行此操作。 –
此外,導致我的東西被打破。我把它放在那裏不知道它到底是什麼,但除了最後一條評論之外,刪除它修復了我的應用程序。 –