【问题标题】:Getting FaultException error after publishing WCF发布 WCF 后出现 FaultException 错误
【发布时间】:2015-12-31 17:05:36
【问题描述】:

我已经为我的一个桌面应用程序开发了 WCF 服务,并使用 DB 托管到 Azure 服务器中。

我刚刚在本地桌面应用程序上连接了 WCF 服务 Url。

一旦我从应用程序调用登录方法。那就没问题了。

一旦我调用了我的第二种方法,我总是得到 FaultException 错误

错误就是这样,详细错误请参见内部异常。但是一旦我进去,那么内部异常就是空的。

我还将<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 放入我的 wcf web.config 中

一旦我将本地 WCF 与 live db 与我的桌面应用程序连接起来,那么一切正常。

一旦我将 Live WCF 与 live db 与我的桌面应用程序连接,则无法插入和更新数据。

我的第二种方法有这个代码。

 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; }
    }

从桌面应用调用上述方法:

  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
                    }

我已经写了 catch 部分然后我也看不到实际的错误。

【问题讨论】:

    标签: c# winforms wcf azure faultexception


    【解决方案1】:

    您可以尝试在故障中包含异常详细信息。将 IncludeExceptionDetailInFaults 设置为 true 以使异常信息能够流向客户端以进行调试。

    阅读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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 2019-02-01
      • 1970-01-01
      • 2023-03-21
      • 2018-12-26
      相关资源
      最近更新 更多