Link to home
Start Free TrialLog in
Avatar of Vrik22
Vrik22

asked on

500 Internal server Issue when making calls between RESTful services

i am using HttpClient call to make requests between the RESTful service calls .
I am migrating my code from MSMQ to RESTful calls to make calls between the RESTful services.
i have developed around 7 RESTful services which internally call each other for updating their respective Databases .
Now ., the common issue i am facing is when i deploy all these services and try to test end point of a service, i am getting 500 internal server error which i understand is due to the internal call failure to other service .

So , now i want to know is there any way where i can make such error handling more specific and get to know which internal service call failed ?
Thanks
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

This works for me as I got similar issues in debugging RESTful web service calls:

1. Try to configure something like below in your web.config:

Under section: system.serviceModel  , add:
    <behaviors>
      <serviceBehaviors>
        <behavior name="debug">
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>
      <service name="your.services.yourclass" behaviorConfiguration="debug" />
    </services>
    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>        
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false"/>
      </webHttpEndpoint>
    </standardEndpoints>

Open in new window


2. Use some logger class to create the logs in your codes.

3. Additionally, in your web method, you may need to do a try catch and then output it for debugging.
Avatar of Vrik22
Vrik22

ASKER

Thanks Ryan, i have already implemented config in that way and i have maintained a Logging class, but still when i try catch , i dont see exact way to catch the exception . I see InnerException as null .
try catch a general exception and debug accordingly? like:

try {
  //your codes here...
}
catch (Exception e)
            {
                logger.Debug(e.Source + ":" + e.Message + ":" + e.StackTrace);
                myClassOutput o = new myClassOutput();
                o.UniqueID = 0;
                o.ErrorMessage = "Your Error Message..";
                o.ReturnValue = 0;
                String json = JsonConvert.SerializeObject(o);
                return WebOperationContext.Current.CreateTextResponse(json, "application/json; charset=utf-8", Encoding.UTF8);
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vrik22

ASKER

I am using C# .NET .i think from RESTful perspective apart from logging we need to debug locally individually check the services and resolve them.