none
WCF hosted in Azure throws System.Net.WebException when client tries to connect RRS feed

  • Question

  • I have a weird problem. Every few weeks, my WCF Web Servie hosted in Azure will throws System.Net.WebException: The remote server returned an error: (500) Internal Server Error.

    Once that happen, I am no longer able to connect to the service. None of the connection will work until I am physically login to Azure portal and restart (stop/start) Azure Cloud Services.

    Recently, I am able to replicate this problem in my local computer during debugging. At one instance, I was debugging a code and I left a debug break point too long (about 15 minutes). I get the following error (on client side) when I tried to connect:

    System.ServiceModel.ProtocolException: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>IIS 10.0 Detailed Error - 500.19 - Internal Server Error</title>
    <style type="text/css">
    <!--
    body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;}
    code{margin:0;color:#006600;font-size:1.1em;font-weight:bold;}
    .config_source code{font-size:.8em;color:#000000;}
    pre{margin:0;font-size:1.4em;word-wrap:break-word;}
    ul,ol{margin:10px 0 10px 5px;}
    ul.first,ol.first{margin-top:5px;}
    fieldset{padding:0 15px 10px 15px;word-break:break-all;}
    .summary-container fieldset{padding-bottom:5px;margin-top:4px;}
    legend.no-expand-all{padding:2px 15px 4px 10px;margin:0 0 0 -12px;}
    legend{color:#333333;;margin:4px 0 8px -12px;_margin-top:0px;
    font-weight:bold;font-size:1em;}
    a:link,a:visited{color:#007EFF;font-weight:bold;}
    a:hover{text-decoration:none;}
    h1{font-size:2.4em;margin:0;color:#FFF;}
    h2{font-size:1.7em;margin:'. ---> System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       --- End of inner exception stack trace ---
    
    Server stack trace:
       at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout)
       at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    
    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.ClientBase`1.Open()
       at WMShared.WMWeb.Login(String username, String password) in C:\PRO\WarehouseManagement\Libraries\WMShared\WMAPIWeb.cs:line 54
       at WMShared.WMWeb.WebReq.Login(String username, String password, XRestServiceClient& xrsClient) in C:\PRO\WarehouseManagement\Libraries\WMShared\Services\WebReq\WebReq.cs:line 100

    It looks like the WCF server is unable to recover?

    In the server, I also get an exception when I tried to start a background worker using Task.Factory.StartNew():

    System.Threading.Tasks.TaskSchedulerException: 'An exception was thrown by a TaskScheduler.'
    
    Inner Exception
    AppDomainUnloadedException: Attempted to access an unloaded AppDomain.

    When I tried to view the service using https://localhost:44300/WarehouseManagementService.svc I get this error:

    Detailed Error Information:
        Module     CustomErrorModule
        Notification       SendResponse
        Handler    Not yet determined
        Error Code     0x80070490
        Config Error       The configuration section 'system.webServer/httpErrors' cannot be read because it is missing a section declaration
        Config File    \\?\C:\Users\shopkins\AppData\Local\dftmp\Resources\aa0cf43d-1904-4c6d-a283-0c6c75c83825\temp\temp\RoleTemp\applicationHost.config

    I am keep getting those error until I physically restart the service.

    Any idea how to recover or restart WCF service again?

    Cheers

    Saturday, February 17, 2018 12:42 PM

All replies

  • It's just a 500 error and not a 500.xx?
    Saturday, February 17, 2018 9:29 PM
  • Hi SamOutlook,

    >>At one instance, I was debugging a code and I left a debug break point too long (about 15 minutes)

    For this error, it seems to be related with timeout error, I suggest you increase Timeout Settings in service side.

    <bindings>
        <netTcpBinding>
          <binding name="longTimeoutBinding"
            receiveTimeout="00:10:00" sendTimeout="00:10:00">
            <security mode="None"/>
          </binding>
        </netTcpBinding>
      </bindings>
    
      <services>
        <service name="longTimeoutService"
          behaviorConfiguration="longTimeoutBehavior">
          <endpoint address="net.tcp://localhost/longtimeout/"
            binding="netTcpBinding" bindingConfiguration="longTimeoutBinding" />
        </service>

    To check the depth error message, I would suggest you enable includeExceptionDetailInFaults as true.

          <serviceBehaviors>
            <behavior name="My">
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>

    In addition, I suggest you enable WCF Tracing.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 19, 2018 12:49 PM