代理出现WebService错误



我有一个带有asp.net web服务(wsdl)的c#win应用程序。如果我启用了代理,应用程序将停止工作,当我查看事件日志查看器时,我看到这个错误:

Framework Sürümü: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ServiceModel.ProtocolException
Stack:
Server stack trace: 
at: System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
at: System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at: System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at: System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at: System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at: System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at: System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
at: System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)
at: System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(System.Runtime.Remoting.Proxies.MessageData ByRef, Int32)
at: MatriksMessenger.MsgService.ServiceSoap.IsBlocked(System.String, System.String, System.String)
at: MatriksMessenger.LoginForm.CallService()
at: System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at: System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at: System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at: System.Threading.ThreadHelper.ThreadStart()

我可以从浏览器访问Web服务。如何找到解决方案?

谢谢,

Win 7,Framework 4.0

听起来Web服务使用的安全/身份验证设置取决于用户与服务在同一域中。

然后,如果您通过代理调用服务,则安全性(用户)通常会丢失。当您在代理上使用basicHttpBinding时就是这种情况,由于这是默认情况,我假设这就是您正在做的。

如果您希望您的Web服务能够对用户进行身份验证,即使用户和服务位于不同的域上,也需要使用另一个绑定,例如ws2007HttpFederationBinding(WIF)。

如果您只需要确保您的代理设置不会妨碍您,您可以更改Windows应用程序的app.config文件中的设置,以便服务调用绕过代理并直接调用服务。这可以通过在app.config中设置绑定规范的属性来完成,请参阅http://msdn.microsoft.com/en-us/library/ms731361.aspx有关可用于basicHttpBinding的属性的详细信息。

应该更改的属性是bypassproxylocal和usedefaultproxy。

我想明白了。我已将此行添加到app.config

<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
</defaultProxy>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>

最新更新