代理的WebService错误

时间:2012-09-27 09:23:33

标签: c# asp.net web-services proxy

我有一个带有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

2 个答案:

答案 0 :(得分:1)

听起来网络服务正在使用安全/身份验证设置,这取决于用户与服务位于同一域中。

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

如果您希望您的网络服务能够对用户进行身份验证,即使用户和服务位于不同的域中,您也需要使用其他绑定,例如: ws2007HttpFederationBinding(WIF)。

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

您应该更改的属性是bypassproxyonlocal和usedefaultproxy。

答案 1 :(得分:1)

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

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