2008-10-29 49 views
5

我的WCF服務改變端點地址結果使用的wsHttpBinding並從客戶端正常工作時,該服務是由客戶端使用默認選項如下gerenated:WCF - 在拋出:SecurityException

RServiceClient R = new RServiceClient(); 

然而,在某些時候,我「會需要能夠指定服務的位置,可能是通過如下改變端點地址:

RServiceClient R = new RServiceClient(); 
R.Endpoint.Address = new EndpointAddress(new Uri "http://xxx.xxxx.xxx:80/RServer/RService.svc")); 

然而,當我做指定精確的終點,我得到一個SecurityNegotiationException: System.ServiceModel。小號ecurity.SecurityNegotiationException未處理 Message =「調用方未被服務認證。」 Source =「mscorlib」....

WCF服務在IIS上運行,並且在IIS管理下啓用匿名訪問。另外,當客戶端與管理帳戶下的服務運行在同一臺機器上時,會發生此錯誤 - 我不知道通過網絡運行它的可怕部分!

任何想法?

回答

8

默認情況下,wsHttpBinding使用Windows身份驗證。我不確定在IIS中託管如何影響這種情況。

如果您不希望啓用安全性,則可以添加一個用於安全性的元素,並將模式元素設置爲「無」,以便兩端的配置關閉默認設置。

我想這可能做的伎倆 - 我已經添加的wsHttpBinding的部分,將bindingConfiguration您的服務指向新添加的綁定屬性:

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="wsHttpBind"> 
      <security mode="None"> 
      <transport clientCredentialType="None" protectionLevel="EncryptAndSign" /> 
      <message clientCredentialType="None" algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="ServiceBehavior" 
      name="RService"> 
      <endpoint address="" 
       binding="wsHttpBinding" 
       bindingConfiguration="wsHttpBind" 
       name="RService" 
       contract="IRService"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
      <endpoint address="mex" 
       binding="mexHttpBinding" 
       name="MetadataExchange" 
       contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="ServiceBehavior"> 
      <!-- 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> 
</system.serviceModel> 
+0

由於一噸...保存我 ;) – kape123 2011-06-13 08:50:51

0

您是否在使用帶證書的MessageSecurity?這可能是一個證書的問題(錯誤的主機名,沒有安裝自簽名證書,等等。)

0

這裏是我的服務配置信息,我使用的WSHttpBinding:

<system.serviceModel> 
    <services> 
    <service behaviorConfiguration="ServiceBehavior" name="RService"> 
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="" 
name="RService" contract="IRService"> 
<identity> 
    <dns value="localhost" /> 
</identity> 
</endpoint> 
<endpoint address="mex" binding="mexHttpBinding" name="MetadataExchange" 
contract="IMetadataExchange" /> 
    </service> 
</services> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="ServiceBehavior"> 
       <!-- 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> 
</system.serviceModel> 
3

檢查這從您的配置:

...  
    <identity> 
     <dns value="localhost" /> 
    </identity> 
... 

據我所知的wsHttpBinding有信息安全默認開啓。 當它檢查dns值「localhost」時,它會失敗。

0

刪除識別塊沒有工作,雖然沒有給我一個想法: 如果我更改從端點地址:

 R.Endpoint.Address = new EndpointAddress(new Uri("http://bigpuss.homeip.net/RServer/RService.svc")); 

 R.Endpoint.Address = new EndpointAddress(new Uri("http://localhost/RServer/RService.svc")); 

然後一切工作正常! Soo,對於非本地的url地址顯然很失望。配置中是否有其他安全設置的區域?

相關問題