通过代理连接WCF到asmx Web服务

4

抱歉,正在输入时未找到答案

我正在尝试通过代理连接需要用户名/密码身份验证的外部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>

我遇到了以下错误:
绑定CustomBinding.http://tempuri.org/针对合同AreaWebServiceSoap.AreaWebServices的配置采用需要具有完整性和机密性的传输级别的验证模式。 传输无法提供完整性和机密性。
抱歉,在输入这个问题时,我偶然发现了答案。 我仍然认为人们可能会对此感兴趣,并且所有评论和想法仍然受到欢迎。 因此,我将在此处保留问题并使其成为社区,并自己发布答案。
2个回答

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”


1

谢谢。这是一个不错的补充。 - KeesDijk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接