2009-08-05 82 views
1

我有一個非常簡單的WCF服務,我想公開公開。我創建了這個服務,並且在沒有太多麻煩的情況下將其設置在我們的服務器上問題是,我們能夠對我們的專用網絡內使用的服務,但是當我們嘗試從網絡外部使用它,下面的錯誤是拋出:WCF驗證問題

安全支持提供程序接口(SSPI)協商失敗。

我做了一些研究,聽起來像WCF默認使用Windows身份驗證。我想將其更改爲不使用身份驗證,但我不完全確定如何。以下是我的配置現在的樣子。

<system.serviceModel> 
    <services> 
     <service behaviorConfiguration="XX.ZZ.WebService.MyServiceBehavior" 
     name="XX.ZZ.WebService.MyService"> 
      <endpoint address="" binding="wsHttpBinding" contract="XX.ZZ.WebService.IMyService"> 
      </endpoint> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="XX.ZZ.WebService.MyServiceBehavior"> 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 

我將不勝感激一些指針,或在正確的方向輕推。

回答

6

那麼,你的服務使用的wsHttpBinding,默認情況下將需要Windows用戶憑據 - 這爲外部用戶顯然不會有。它本身不是WCF,默認情況下使用Windows憑據(如您所述),但實際上是這種特定綁定(wsHttpBinding) - 其他人可能會默認使用其他設置。

你有兩個選擇:

  • 配置的wsHttpBinding(這是相當「重量級」)使用無安全性可言,或者使用用戶名/密碼的安全性,其中呼叫者就必須提供
  • 使用basicHttpBinding的沒有安全,而不是(這是ASMX模型,基本上)

要的wsHttpBinding完全關閉安全,這包括在你的配置:

<bindings> 
    <wsHttpBinding> 
    <binding name="NoSecurity"> 
     <security mode="None" /> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

,然後配置你的端點使用綁定配置:

<system.serviceModel> 
    <services> 
     <service name="XX.ZZ.WebService.MyService" 
       behaviorConfiguration="XX.ZZ.WebService.MyServiceBehavior"> 
      <endpoint address="" 
        binding="wsHttpBinding" 
        bindingConfiguration="NoSecurity" 
        contract="XX.ZZ.WebService.IMyService"> 
      </endpoint> 
      <endpoint address="mex" 
         binding="mexHttpBinding" 
         contract="IMetadataExchange" /> 
     </service> 
    </services> 

你可以做同樣的<basicHttpBinding>,而不是如果你想<wsHttpBinding>(有使用的wsHttpBinding與basicHttpBinding的,如果你原來沒有好處關閉安全以及wsHttpBinding提供的所有其他更高級功能)。

還有一個非常好的blog post series,在五個不同的,典型的場景方面談談WCF安全的基本知識 - 優秀的讀!

馬克

+0

只是遇到同樣的問題,儘管可能沒有「沒有任何好處」,但爲什麼有些人可能希望使用wsHttpBinding有一定的區別。 http://stackoverflow.com/questions/2106715/basichttpbinding-vs-wshttpbinding – 2013-08-21 08:50:18

2

WCF可以是一個真正的痛苦,當談到配置它。看看WCFSecurity它爲不同的配置環境提供了很好的工作示例。

+0

看看我在答覆中提到的博客文章 - 他們真的有很大的幫助,使WCF安全一樣容易採摘的這五個場景之一 - 真! :-) – 2009-08-05 14:56:30

+0

博客文章沒問題,但他們只涵蓋基本情況。WCF安全指導更加全面,涵蓋深入的主題。 – Ray 2009-08-05 15:09:51

+1

嗯,重點是:這些博客文章涵蓋了基本的五種情況,涵蓋了大約90%的用例。 WCF安全指南涵蓋了所有可能的功能組合 - 但是您真的需要這些嗎?由於它們覆蓋了一切,這是你可能淹沒的大量信息..... – 2009-08-05 17:18:35

2

這給你傳輸級安全性,沒有身份驗證:

<configuration> <system.serviceModel> 
    <services> 
     <service 
      name="Microsoft.ServiceModel.Samples.CalculatorService" 
      behaviorConfiguration="CalculatorServiceBehavior"> 
     <endpoint address="" 
        binding="wsHttpBinding" 
        bindingConfiguration="Binding1" 
        contract="Microsoft.ServiceModel.Samples.ICalculator" /> 
     </service> 
    </services> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="Binding1"> 
      <security mode="Transport"> 
      <transport clientCredentialType="None"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="CalculatorServiceBehavior"> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> </system.serviceModel> 
</configuration> 

其他情況我會看看Microsoft WCF samples

+0

你能告訴我你如何實現沒有證書的運輸安全嗎?這個答案沒有意義。 – SomeRandomName 2017-01-23 15:18:24