2015-10-08 68 views
0

我有一個WCF服務,使用basicHttpBinding的和Windows身份驗證(不匿名),使用WCF與basicHttpBinding的和Windows身份驗證

WCF服務在域服務器 託管我需要從一個服務器使用服務這是超出域,該服務器不加入域,這是一個工作組。那可能嗎?請爲代碼片段提供幫助。

像下面

<bindings> 
    <basicHttpBinding> 
    <binding name="defaultBinding" receiveTimeout="01:00:00" sendTimeout="01:00:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> 
     <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" /> 
     <security mode="TransportCredentialOnly"> 
     <transport clientCredentialType="Windows"/> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="defaultServiceBehavior"> 
     <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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> 
<services> 
    <service behaviorConfiguration="defaultServiceBehavior" name="namespace.MyService"> 
    <endpoint binding="basicHttpBinding" bindingConfiguration="defaultBinding" contract="namespace.IMyService"> 
     <identity> 
     <dns value="abc.xyz.com"/> 
     </identity> 
    </endpoint> 
    </service> 
</services> 

編輯的配置:這裏是我的客戶端代碼

_securityServiceClient = new SecurityServiceClient(); 
_securityServiceClient.ClientCredentials.UserName.UserName = "lto3"; 
_securityServiceClient.ClientCredentials.UserName.Password = "[email protected]"; 

我得到這個錯誤

型System.ServiceModel.Security的」異常。 MessageSecurityException'發生在mscorlib.dll中,但未在用戶代碼中處理

附加信息:HTTP請求在客戶端 「基本」身份驗證方案中未經授權。從 服務器收到的驗證頭是「Negotiate,NTLM」。

+0

這是所有WCF教程中介紹的最基本的場景之一。你有什麼嘗試,有什麼問題?客戶代碼在哪裏? –

+0

您好,感謝您的期待,我收到了此消息{「該HTTP請求未經客戶端身份驗證方案'Basic'授權,從服務器收到的身份驗證頭是'Negotiate,NTLM'。}}這裏是我的客戶端代碼_securityServiceClient = new SecurityServiceClient(); _securityServiceClient.ClientCredentials.UserName.UserName =「domain \\ account」; _securityServiceClient.ClientCredentials.UserName.Password =「password」; – khoailang

+0

你好,可以請指教 – khoailang

回答

0

嘗試使用:

_securityServiceClient.ClientCredentials.Windows.ClientCredential = 
      new NetworkCredential("lto3", "[email protected]"); 

按照該msdn documentation ClientCredentials.Windows是如何指定使用Windows身份驗證時使用的憑據。

+0

謝謝,但是這個屬性是隻讀ClientCredentials.Windows.ClientCredential – khoailang

+0

哦,我得到了「只讀」異常,只是2次現在它消失了:( – khoailang

+0

你得到只讀異常,如果你'我們已經使用過客戶端了,一旦調用,憑證對象就成爲只讀的。 – MattC