2016-10-05 39 views
0

我有一個我正在嘗試使用的SOAP,但遇到下一個問題,我沒有在類似問題中找到解決方案:
SOAP必須通過HTTPS和Windows憑據調用。配置winform應用程序使用windows驗證調用SOAP https

我試圖在應用程序配置做的是接下來的事情:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpsBinding> 
     <binding name="WebServiceSoap"> 
      <security mode="TransportWithMessageCredential"> 
      <transport clientCredentialType="Windows" /> 
      <message clientCredentialType="UserName"/> 
      </security> 
     </binding> 
     </basicHttpsBinding> 
    </bindings> 
    <client> 
     <endpoint address="https://someapp/SDK/WebService.asmx" 
     binding="basicHttpsBinding" bindingConfiguration="WebServiceSoap" 
     contract="someapp_contract.WebServiceSoap" name="WebServiceSoap" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

而我得到的是錯誤:

The username is not provided. Specify username in ClientCredentials.And the error 

我嘗試了differt confingruation太有basicHttpBinding的

<security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Windows" /> 

但比這是我得到的錯誤的是(這是一個非常邏輯錯誤):

provided URI scheme 'https' is invalid; expected 'http'... 

沒有人在過去同樣的問題?

在此先感謝。
最大

P.S:
如果我做的

<security mode="TransportWithMessageCredential"> 

我得到下一個錯誤

<security mode="Transport"> 

代替:

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'. 

回答

0

按照上面的設置。
當我使用:

<security mode="Transport"> 

並且得到錯誤:

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'. 

我沒有什麼未來的變化。
1)首先在app.config中

<security mode="Transport"> 
    <transport clientCredentialType="Windows" /> 
    <message clientCredentialType="UserName" algorithmSuite="Default" /> 
</security> 

比代碼:

public static class Ssl 
{ 
    private static readonly string[] TrustedHosts = new[] { 
     "YourServiceName", 
     "YourServiceName2" 
    }; 

    public static void EnableTrustedHosts() 
    { 
     ServicePointManager.ServerCertificateValidationCallback = 
     (sender, certificate, chain, errors) => 
     { 
      if (errors == SslPolicyErrors.None) 
      { 
       return true; 
      } 

      var request = sender as HttpWebRequest; 
      if (request != null) 
      { 
       return TrustedHosts.Contains(request.RequestUri.Host); 
      } 

      return false; 
     }; 
    } 
} 

和:

YourContractInstance.ClientCredentials.Windows.ClientCredential.UserName = ***; 
YourContractInstance.ClientCredentials.Windows.ClientCredential.Domain = ***; 
YourContractInstance.ClientCredentials.Windows.ClientCredential.Password = ***; 
YourContractInstance.ClientCredentials.Windows.AllowNtlm = true; 

所有這些解決辦法的提出是因爲我有一些問題我不允許訪問SOAP服務主機上的證書| DNS配置,因此我必須通過IP添加服務引用。

相關問題