簡體   English   中英

通過代理連接到帶有WCF的asmx Web服務

[英]Connecting to an asmx webservice with WCF through a proxy

輸入時發現抱歉的答案

我正在嘗試連接到需要通過代理進行用戶名/密碼身份驗證的外部Web服務。 我正在使用Visual Studio Express 2008生成服務引用

  • 我使用Web引用連接到同一個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>

我已將以下代碼添加到我的身份驗證調用中:

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>

我收到以下錯誤:

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

對不起,在輸入這​​個問題時,我自己偶然發現了答案。 我仍然認為人們可能對此感興趣,所有的評論和想法仍然受到歡迎。 所以我會在這里留下問題並將其作為社區並自己發布答案。

將綁定更改為:

<?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”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM