简体   繁体   中英

Getting FaultException error after publishing WCF

I have developed WCF service for my one of the desktop application and host into Azure server with DB.

I have just connect WCF service Url on my local Desktop application.

Once i called login method from application. then no issue.

Once i called my second method then always i got FaultException error

Error is like that see the inner exception for detail error. but once i go inside then inner exception is null.

I also put <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> into my wcf web.config

Once i connect local WCF with live db with my desktop app then everything is work fine.

Once i connect Live WCF with live db with my desktop app then not working insert and update data.

my second method having this code.

 public class Service1 : IService1
    {
     public void method1(int nm_Id, string f_LoginStatus)
            {
                class1 lo_class = new class1();

                    DateTime dt = DateTime.UtcNow;
                    //check records exist or not
                        lo_class.dt_date = dt;
                        lo_class.dtCreatedOn = dt;
                        lo_tblAttendance.dtUpdatedOn = dt;

                        _context.tblAttendances.Add(lo_tblAttendance);

                        Save();
                    }
           }
    }

 [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [FaultContract(typeof(InitializationFault))]
        void method1(int nm_Id, string f_LoginStatus);
     }


   [DataContract]
    public class InitializationFault
    {
        public InitializationFault(Exception exc, string msg)
        {
            Exception = exc;
            Message = msg;
        }

        [DataMember]
        public Exception Exception { get; set; }

        [DataMember]
        public string Message { get; set; }
    }

Calling above method from desktop app:

  lo_loginServices = new MyService.Service1Client();
  try
                    {
                        lo_loginServices.method1(lo_EmpId, "In"); // getting inner exception error here
                    }
                    catch (FaultException<InitializationFault> ex)
                    {
                        Console.WriteLine("FaultException<InitializationFault>: " + ex.Detail);
                        //more
                    }

I've write catch section then also i can't able to see actual error.

You may try to Include Exception Details in Fault. Setting IncludeExceptionDetailInFaults to true to enables exception information to flow to clients for debugging purposes.

Read here

<configuration>  
<system.serviceModel>  
  <services>  
    <!-- Step 1. Add a behaviorConfiguration attribute --> 
    <service  
      name="Microsoft.WCF.Documentation.SampleService"  
      behaviorConfiguration="metadataAndDebug">  
      <host>  
        <baseAddresses>  
          <add baseAddress="http://localhost:8080/SampleService" />  
        </baseAddresses>  
      </host>  
      <endpoint  
         address="mex"  
         binding="mexHttpBinding"  
         contract="IMetadataExchange"  
      />  
    </service>  
  </services>  
  <behaviors>  
    <serviceBehaviors>  
      <!-- Step 2. Add a new behavior below.-->
      <behavior name="metadataAndDebug">  
        <serviceMetadata  httpGetEnabled="true" httpGetUrl=""/>  
      <!-- Step 3. Add a <serviceDebug> element -->
    <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />  
      </behavior>  
    </serviceBehaviors>  
  </behaviors>  
</system.serviceModel>  
</configuration>

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