2010-07-14 80 views
4

當我在Visual Studio中添加一個服務引用到一個服務時,它不斷添加這個extendedProtectionPolicy到我的安全綁定,它在我的Win7機器上工作正常。但是當我部署到Server 2003時,它錯誤地指出配置文件中無法識別的元素。Visual Studio「添加服務引用」不斷添加「extendedProtectionPolicy」到我的配置文件

刪除行<extendedProtectionPolicy policyEnforcement="Never" />修復了錯誤。

這是後產生不希望的web.config中的整個部分的添加服務引用(客戶端)

<security mode="TransportWithMessageCredential"> 
    <transport clientCredentialType="None" proxyCredentialType="None" 
     realm=""> 
     <extendedProtectionPolicy policyEnforcement="Never" /> 
    </transport> 
    <message clientCredentialType="UserName" algorithmSuite="Default" /> 
</security> 

這是我的服務正在使用的行爲(IIS7主機側)

<behavior name="GetHttpsIncludeFaults"> 
    <serviceCredentials> 
    <userNameAuthentication 
     userNamePasswordValidationMode="Custom" 
     customUserNamePasswordValidatorType="MyCustomValidator, MyOtherAssembly"/> 
    </serviceCredentials> 
    <serviceMetadata httpsGetEnabled="true" /> 
    <serviceDebug includeExceptionDetailInFaults="true" /> 
</behavior> 

我想指出一些事情。這發生在VS2010和VS2008中。這發生在Consumer-Projects的ASP.NET-MVC風格AS和Windows Service/WPF應用程序中。

+0

我想補充一點,該錯誤也適用於Windows Vista。 – 2010-07-14 16:37:52

回答

3

據我可以從互聯網上找到的信息和更具體的微軟連接來得知,這是一個尚未確定的已知問題。

您可以通過使用Visual Studio 2010的配置變換功能來解決此問題。配置變換是一個非常有用的功能,允許您在部署應用程序時自動更改配置文件的內容(如連接字符串)。

不幸的是,目前配置轉換隻支持web.config文件。然而,This blogpost解釋瞭如何使用Config Transforms for app.config文件。

下面的變換應該解決您的問題:

<?xml version="1.0"?> 
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding> 
      <security> 
      <transport> 
       <extendedProtectionPolicy xdt:Transform="Remove" /> 
      </transport> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    </system.serviceModel> 
</configuration> 

正如你所看到的,在部署應用程序時刪除<extendedProtectionPolicy/>節點。

+0

我應該補充一點,在VS2010中,違規行被「突出顯示」,因爲不是預期的,但它並不會提醒任何異常。在其他系統上,拋出了一個實際的異常。另外我的消費者是一個Windows服務... – Nate 2010-07-14 17:37:14

+0

因此,我認爲你使用VS2010?您可能需要爲其添加標籤或相應地編輯您的問題。 – 2010-07-14 17:41:55

+0

是............ – Nate 2010-07-14 17:43:54

相關問題