通过代理连接到与WCF的Web服务ASMX
问题描述:
对不起答案,打字时通过代理连接到与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是配置有验证模式,其中需要具有完整性和机密性的传输级别。运输不能提供完整性和保密性。
对不起,在输入此问题时,我自己偶然发现了答案。我仍然认为人们可能对此感兴趣,所有的评论和想法仍然受到欢迎。所以我会在这里留下问题,并让它成为社区并自己发布答案。
答
更改绑定到:
<?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”
感谢。这是一个很好的补充, – KeesDijk 2009-01-01 10:55:23