通过代理连接使用WCF的web服务ASMX [英] Connecting to an asmx webservice with WCF through a proxy
问题描述
在键入时发现的对不起答案
我试图连接到通过代理服务器需要用户名/密码认证的外部Web服务。我使用Visual Studio的前preSS 2008年生成服务引用
I am trying to connect to an external webservice that requires username/password authentication through a proxy. I am using Visual Studio Express 2008 to generate a service reference
- 我已连接到相同的
使用网络,电压,web服务
只有设置更大的超时
因为它需要很长的时间来
完。 - 我已经连接到另一个
web服务不需要
用户名/密码认证
用生成的服务参考
还有一些设置,以获得它通过
代理。
所以,我的思想会
借此参考,其指向
正确的web服务并添加
验证。
So my thought would be to take this reference, point it to the correct webservice and add authentication.
我使用的配置没有安全:
The config I am using without security:
<?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以下code我的电话进行验证:
I have added te following code to my call for authentication:
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();
}
就在使用这种设置使预期的错误:
Just using this setup gives an error as expected:
的 HTTP请求未被授权使用客户端身份验证方案匿名。来自服务器的身份验证标头收到,是NTLM。的
现在我迷路了,并开始尝试,因为我刚开始使用WCF无聊的事。
Now I get lost and start trying silly things because I am just starting to use WCF.
当我添加以下部分到config
When I add the following section to the config
<security authenticationMode="UserNameOverTransport"></security>
我收到以下错误:
I get the following error:
的绑定CustomBinding.http:/ / tempuri.org /为合同AreaWebServiceSoap.AreaWebServices配置与它需要传输层与完整性和机密性验证模式。运输不能提供的完整性和保密性。的
很抱歉,同时键入这个问题我偶然发现自己的答案。我仍然认为人可能对此感兴趣,所有的意见和想法,仍然欢迎。因此,我将离开这里的问题,并使其社区和张贴自己的答案。
Sorry, while typing this question I stumbled upon the answer myself. I still think people might be interested in this and all comments and thoughts are still welcome. So I will leave the question here and make it community and post the answer myself.
推荐答案
更改绑定:
<?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
So set authenticationScheme="Ntlm"
这篇关于通过代理连接使用WCF的web服务ASMX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!