简体   繁体   English

发布WCF后出现FaultException错误

[英]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. 我已经为我的桌面应用程序之一开发了WCF服务,并通过DB托管到Azure服务器中。

I have just connect WCF service Url on my local Desktop application. 我刚刚在本地桌面应用程序上连接了WCF服务网址。

Once i called login method from application. 一旦我从应用程序调用登录方法。 then no issue. 那没问题

Once i called my second method then always i got FaultException error 一旦我调用了第二种方法,那么总会出现FaultException错误

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 我还将<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />放入我的wcf web.config中

Once i connect local WCF with live db with my desktop app then everything is work fine. 一旦我使用桌面应用程序将本地WCF与实时数据库连接起来,那么一切就可以正常工作。

Once i connect Live WCF with live db with my desktop app then not working insert and update data. 一旦我通过桌面应用程序将Live WCF与实时数据库连接起来,则无法正常工作,无法插入和更新数据。

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. 我写了catch部分,然后我也看不到实际错误。

You may try to Include Exception Details in Fault. 您可以尝试在“故障”中包括异常详细信息。 Setting IncludeExceptionDetailInFaults to true to enables exception information to flow to clients for debugging purposes. IncludeExceptionDetailInFaults设置为true可以使异常信息流到客户端以进行调试。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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