2015-12-31 51 views
0

我爲我的一個桌面應用程序開發了WCF服務,並使用數據庫將其託管到Azure服務器中。發佈WCF後發生FaultException錯誤

我剛剛在本地桌面應用程序上連接了WCF服務Url。

一旦我從應用程序調用登錄方法。那麼沒問題。

一旦我打電話給我的第二個方法則總是我得到的FaultException錯誤

錯誤就像是看到詳細的錯誤內部異常。但是一旦我進入內部,那麼內部異常就是空的。

我也把<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />到我的WCF的web.config

一旦我的本地WCF與我的桌面應用程序實時數據庫連接,然後一切都做工精細。

一旦我連接Live WCF與Live數據庫與我的桌面應用程序,然後不工作插入和更新數據。

我的第二個方法有這個代碼。

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 
        } 

我已經寫保持部分則還我不能看到實際的錯誤。

回答

0

您可能會嘗試在異常中包含異常詳細信息。設置IncludeExceptionDetailInFaultstrue使異常信息流到客戶端用於調試目的。

閱讀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>