【发布时间】:2011-07-04 12:11:21
【问题描述】:
我遇到了连接 Web 服务的基本身份验证问题,该服务是在 Visual Studio 中从 ChannelBase 派生的。已经尝试在MSDN中询问没有结果,所以我在这里碰碰运气。
这是场景:
a) Web 服务需要基本身份验证(用户名和密码)并支持 SOAP 1.1
b) 我必须通过 HTTP 代理,这又需要基本身份验证。
我无法让它工作:Web 服务上的身份验证很好(如果测试绕过代理)但看起来我无法配置 ChannelBase 派生类来处理代理上的身份验证(在获得所需的身份验证之后HTTP 响应,它不会继续协商身份验证)。
这是我在 app.config 中的当前设置
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="LocationWSBinding" receiveTimeout="00:02:30">
<textMessageEncoding messageVersion="Soap11" />
<httpTransport authenticationScheme="Basic" proxyAddress="http://The.proxy.ip" useDefaultWebProxy="false"
bypassProxyOnLocal="True" proxyAuthenticationScheme="Basic" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://the.web.service"
binding ="customBinding" bindingConfiguration="LocationWSBinding"
contract="The.Contract.Name" name="LocationWSPort" />
</client>
</system.serviceModel>
</configuration>
在代码中,这是我指定凭据的地方:
TheClient WS = new TheClient("LocationWSPort");
WS.ClientCredentials.UserName.UserName = "WebServiceUsername";
WS.ClientCredentials.UserName.Password = "WebServicepassword";
WS.ChannelFactory.Credentials.Windows.ClientCredential = new NetworkCredential("Proxyusername","ProxyPassword");
你能帮帮我吗?
我不知道是什么问题阻止了客户端在请求时继续进行代理身份验证。
感谢伊曼纽尔
Enrico,抱歉回复晚了。 我已尝试遵循您的建议,并且仅当我调用不带参数的 web 服务方法时才有效,当我调用需要复杂类型作为参数的方法时(这是我必须进行的真正调用才能获得有用的有效负载),我得到以下信息错误:
{"The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."}
[System.ServiceModel.CommunicationException]: {"The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."}
_className: null
_data: {System.Collections.ListDictionaryInternal}
_dynamicMethods: null
_exceptionMethod: null
_exceptionMethodString: null
_helpURL: null
_HResult: -2146233087
_innerException: null
_ipForWatsonBuckets: 83189596
_message: "The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."
_remoteStackIndex: 1
_remoteStackTraceString: "\r\nServer stack trace: \r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException rethrown at [0]: \r\n"
_safeSerializationManager: {System.Runtime.Serialization.SafeSerializationManager}
_source: null
_stackTrace: {sbyte[80]}
_stackTraceString: null
_watsonBuckets: null
_xcode: -532462766
_xptrs: 0
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
HResult: -2146233087
InnerException: null
IsTransient: false
Message: "The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."
Source: "mscorlib"
StackTrace: "\r\nServer stack trace: \r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException rethrown at [0]: \r\n at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n at [.......] in E:\\VisualStudioPrj\\HTTPproxyTroubleshoot\\HTTPproxyTroubleshoot\\Program.cs:line 88"
TargetSite: {Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)}
现在,我确信数据协定没问题(如果我没有设置 WebRequest.DefaultWebProxy,它就可以工作)。 至于 FTP,嗯,这些 SOAP 调用是由 Windows 服务运行的两个线程之一完成的将被格式化为破坏 FTP 通信的 HTML...
【问题讨论】:
标签: wcf authentication proxy wcf-client