2010-07-21 26 views
0

我想通過WCF Web服務公開,使用用戶的憑據訪問SQL服務器(通過實體框架)的功能(這是一個客戶端/ DBA的要求,因爲審計觸發器等)讓人試圖說服他們不使用用戶的憑據)使用WCF模仿

我無法讓WCF實現模擬。 (實際上它是一場噩夢)。我添加了

[OperationBehavior(Impersonation = ImpersonationOption.Allowed)] 

屬性到我的合同。但後來它抱怨BasicHttpContract無法進行窗口模擬。我試圖將其改爲wsHttpBinding。現在元數據交換被打破了。到目前爲止,我只是試圖在Internet Explorer中打開這些服務,甚至還沒有開始與客戶端連接。 web.config中的相關部分看起來像下面

<behaviors> 
    <serviceBehaviors> 
    <behavior name="AssetManagerBehavior"> 
     <serviceAuthorization impersonateCallerForAllOperations="true" /> 
     <!-- 
     --> 
     <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
     <serviceMetadata httpGetEnabled="true" /> 
     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

    <services> 
     <service name="AssetManager.ServiceInterface" behaviorConfiguration="AssetManagerBehavior"> 
      <endpoint address="" binding="wsHttpBinding" contract="IAssetServices"> 
      </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 

<bindings> 
    <wsHttpBinding> 
    <binding name="test"> 
     <security mode="TransportWithMessageCredential" /> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

相關的服務接口類看起來如此

namespace AssetManager.ServiceInterface 
{ 
[ServiceContract] 
public interface IAssetServices 
    { 
     [OperationContract] 
     EmployeeDTO CreateNewEmployee(string firstName, string lastName); 
    } 
} 

實際的實現看起來像這樣

namespace AssetManager.ServiceInterface 
{ 
public class AssetManagerServices : IAssetServices 
{ 

    #region IAssetServices Members 

    [OperationBehavior(Impersonation = ImpersonationOption.Allowed)] 
    public EmployeeDTO CreateNewEmployee(string firstName, string lastName) 
    { 
    } 
} 
} 

我使用VS 2010 ,.net 4,IIS 7(啓用了以下身份驗證 - 匿名,ASP.NET模擬,基本身份驗證,摘要式身份驗證和Windows身份驗證)。在IIS的根網絡服務器上,我點擊了ISAPI和CGI限制,並允許訪問所有的擴展名(asp.net 4.0可能是相關的)

我目前的障礙是它說:「此服務的元數據發佈是目前禁用「當我瀏覽到IE中的位置。這也不允許我添加服務引用。

作爲最後一點,確實要做windows冒充應該不是件難事。使用WCF模擬Web服務的建議方式是什麼?在asp.net的世界中,它就像添加<authentication mode="Windows"/><identity impersonate="true"/>

回答

0

一樣簡單如果您使用傳輸級安全性,那麼它將使用https協議,而不是http。

您需要設置

<serviceMetadata httpsGetEnabled=true /> 

(您目前只有httpGetEnabled)。

+0

不,那是行不通的。現在我得到了「此服務的安全設置需要'匿名'身份驗證...」例外。我已關閉IIS中的匿名身份驗證,以便讓客戶端模擬進行。我可以得到它的工作的唯一方法是改變wsBinding到basicBinding並使用此 <安全模式=「TransportCredentialOnly」> <運輸clientCredentialType =的「Windows」 /> 但現在,我無法添加服務引用到我的前端項目,因爲它給我一個錯誤,說「元數據包含一個引用,無法解析http請求在未經授權的匿名」 – Chaitanya 2010-08-03 11:40:29