简体   繁体   中英

Call WCF method OnUnload of ASP.NET page

I want call a WCF method when application exit, but, when I try to run ASP.NET application with this code:

protected override void OnUnload(EventArgs e)
{
    base.OnUnload(e);

    MaChatServer.Service1Client proxy = new MaChatServer.Service1Client();
    proxy.RemoveUser(UsernameStatic);
    if (proxy.GetAllUsers().Count == 0)
    {
        proxy.ResetServer();
    }
}

I see this error page:

Description: An unhandled exception occurred during the execution of the current web request. For more information about the error and where it originated in the code, refer to the stack trace. Exception Details: System.ServiceModel.FaultException: The server was unable to process the request two to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.

Firstly i suggest you to add config to your host wcf service (.config)

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="debug">
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Because you don't have exact error message, your message must be sent to your client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM