2008-11-14 68 views
4

對不起答案,打字時通過代理連接到與WCF的Web服務ASMX

我試圖連接到通過代理服務器需要用戶名/密碼認證外部Web服務發現。我使用的Visual Studio Express 2008的生成服務參考

  • 我已經連接到使用網絡,電壓, 相同 web服務只需要設置一個較大的超時 因爲它需要很長的時間來完成 。
  • 我已經連接到另一個 web服務,不需要 用戶名/密碼認證 與生成的服務參考 和一些設置通過 代理得到它。

所以,我的思想會 藉此參考,它指向 正確的web服務並添加 認證。

我使用沒有安全的配置:

<?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
     <system.net> 
     <defaultProxy useDefaultCredentials="true"> 
      <proxy bypassonlocal="False" proxyaddress="http://***.***.****:80" /> 
     </defaultProxy> 
     </system.net> 
     <system.serviceModel> 
      <bindings> 
      <customBinding> 
       <binding name="AreaWebServiceSoap12"> 
       <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" 
        messageVersion="Soap12" writeEncoding="utf-8"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       </textMessageEncoding>    
       <httpTransport manualAddressing="false" maxBufferPoolSize="524288" 
        maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" 
        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
        keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" 
        realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" 
        useDefaultWebProxy="true" />    
       </binding> 
      </customBinding> 
      </bindings> 
      <client> 
      <endpoint address="http://www.****.*****.****.com/samplewebservice/service.asmx" 
        binding="customBinding" bindingConfiguration="AreaWebServiceSoap12" 
        contract="ServiceReference1.ServiceSoap" name="ServiceSoap" /> 
      </client> 
     </system.serviceModel> 
    </configuration> 

我加入TE下面的代碼我的電話進行驗證:

static void Main(string[] args) 
{ 
    ServiceSoapClient s = new ServiceSoapClient(); 
    s.ClientCredentials.UserName.UserName = @"username"; 
    s.ClientCredentials.UserName.Password = @"password"; 

    Service.RawGpsData[] result = s.GetRawGpsData(0); 
    Console.WriteLine(String.Format("done:{0}",result.Length)); 
    Console.ReadLine(); 
} 

就使用這種設置使預期的錯誤:

HTTP請求未經客戶端身份驗證方案Anonymous授權。收到來自服務器的認證頭文件是NTLM。

現在我迷路了,開始嘗試愚蠢的事情,因爲我剛開始使用WCF。

當我在下一節添加到配置

<security authenticationMode="UserNameOverTransport"></security> 

我得到以下錯誤:

結合CustomBinding.http://tempuri.org /對於合同AreaWebServiceSoap.AreaWebServices是配置有驗證模式,其中需要具有完整性和機密性的傳輸級別。運輸不能提供完整性和保密性。

對不起,在輸入此問題時,我自己偶然發現了答案。我仍然認爲人們可能對此感興趣,所有的評論和想法仍然受到歡迎。所以我會在這裏留下問題,並讓它成爲社區並自己發佈答案。

回答

4

更改綁定到:

<?xml version="1.0" encoding="utf-8" ?> 
<customBinding> 
      <binding name="AreaWebServiceSoap12" closeTimeout="00:01:00" openTimeout="00:10:00" 
        receiveTimeout="00:20:00" sendTimeout="00:05:00"> 
       <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" 
        messageVersion="Soap12" writeEncoding="utf-8"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       </textMessageEncoding>    
       <httpTransport manualAddressing="false" maxBufferPoolSize="524288" 
        maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Ntlm" 
        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
        keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" 
        realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" 
        useDefaultWebProxy="true" />    
      </binding> 
      </customBinding> 

所以設置authenticationScheme = 「NTLM」