2013-10-03 24 views
1

WCF服務時,我有一個WinForms應用程序消耗託管遠程服務器上的WCF服務。當我運行應用程序,它運行和加載數據,但它顯示了以下MessageSecurityException後30秒以上的運行:MessageSecurityException試圖訪問距離的WinForms

安全處理器是無法找到在 消息的安全頭。這可能是因爲該消息是不安全的錯誤或 ,因爲通信方之間存在綁定不匹配。 如果服務配置了安全性並且 客戶端未使用安全性,則會發生這種情況。

我的服務配置是:

<system.serviceModel> 
    <!-- change --> 
    <bindings> 
     <customBinding> 
     <binding name="Wrabind" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:25:00"> 
      <textMessageEncoding/> 
      <security authenticationMode="SecureConversation" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"> 
      <localClientSettings maxClockSkew="00:30:00" /> 
      <localServiceSettings maxClockSkew="00:30:00" /> 
      <secureConversationBootstrap messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"> 
       <localClientSettings maxClockSkew="00:30:00" /> 
       <localServiceSettings maxClockSkew="00:30:00" /> 
      </secureConversationBootstrap> 
      </security> 
      <httpTransport maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000" allowCookies="true" maxBufferSize="20000000" keepAliveEnabled="false" /> 
     </binding> 
     </customBinding> 
    </bindings> 
    <!-- change --> 
    <services> 
     <service behaviorConfiguration="WServiceCoreService.Service1Behavior" name="WServiceCoreService.Service1"> 
     <endpoint address="http://subdomain.domain.com/service1.svc" binding="customBinding" bindingConfiguration="Wrabind" contract="WServiceCoreService.IService1" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WServiceCoreService.Service1Behavior"> 
      <serviceThrottling 
maxConcurrentCalls="200" 
maxConcurrentSessions="200" 
maxConcurrentInstances="200" /> 
      <!-- To avoid disclosing metadata information, set the value below to false before deployment --> 
      <serviceMetadata httpGetEnabled="false" /> 

      <!-- 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> 
     <baseAddressPrefixFilters> 
     <add prefix="http://subdomain.domain.com/" /> 
     </baseAddressPrefixFilters> 
    </serviceHostingEnvironment> 


    </system.serviceModel> 

我的WinForms客戶端配置爲:

<system.serviceModel> 

    <bindings> 
     <wsHttpBinding> 
     <binding name="CustomBinding_IService1" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000" allowCookies="true" closeTimeout="00:05:00" openTimeout="00:05:00" sendTimeout="00:25:00"> 
      <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 

     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://subdomain.domain.com/service1.svc" binding="wsHttpBinding" 
     bindingConfiguration="CustomBinding_IService1" contract="WCoreService.IService1" 
     name="CustomBinding_IService1"> 
     <identity> 
      <userPrincipalName value="WIN-489ESBTC0A0\servewranglein_web" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 

我無法預測什麼是具有這種配置的錯誤。請儘快幫我解決這個問題。

更新:我使用.NET 4.0

+0

嘗試在客戶端和服務器中使用完全相同的配置。還打開wcf trace來查看服務器端的錯誤。 –

回答

0

請儘量enableUnsecuredResponse在客戶端設置爲true,讓我知道它的工作與否。 有關更多詳細信息,請參閱此http://support.microsoft.com/kb/971493

+0

我在哪裏設置它在客戶端配置?你能編輯我的客戶端配置嗎?因爲我的客戶端安全標籤中沒有看到類似這樣的屬性。我正在研究.NET 4 –

+0

我不知道爲什麼你在客戶端配置中有wsHttpBinding,因爲你在服務配置中使用自定義綁定。我認爲你應該在客戶端使用自定義綁定,因爲這個enableUnsecuredResponse屬性只適用於customBinding。請仔細閱讀鏈接我有我在我當前的項目使用此屬性given.Anyway <綁定名稱= 「bindingName」> authenticationMode =」MutualCertificate「> – mit

+0

您是否嘗試過enableUnsecuredResponse = false with customBinding? – mit

0

試試這個(主機和客戶機):

<binding name="XXXXX"> 
     <security mode="None" > 
     <transport clientCredentialType="None" /> 
     <message establishSecurityContext="False" /> 
     </security> 
    </binding> 
+0

沒有工作。這之後甚至沒有連接到WCF服務。 –

0

在我的情況下在主機配置文件中的audienceUris標籤添加服務解決了該問題具有相同的異常。

<system.identityModel> 
... 
    <identityConfiguration> 
    ... 
     <audienceUris> 
      <add value="serviceName.svc" /> 
     </audienceUris> 
    ... 
    </identityConfiguration> 
... 
</system.identityModel>