WCF中的自訂類中包括自訂枚舉類型時出錯

來源:互聯網
上載者:User

現有自訂類型EventLogItem:

View Code

public class EventLogItem
{
public int EventID
{
get;
set;
}
public EventLevel EventType
{
get;
set;
}
public string EventTime
{
get;
set;
}
public string EventTask
{
get;
set;
}
public string EventUser
{
get;
set;
}
public string EventSource
{
get;
set;
}
public string EventIP
{
get;
set;
}
public string EventMessage
{
get;
set;
}
}

自訂枚舉類型EventLevel:

View Code

public enum EventLevel
{
Warning,
Infomation
}

WCF中定義的函數:

View Code

//sqlCore.getUserLogs()傳回型別為List<EventLogItem>
[OperationContract]
public List<EventLogItem> getLogs()
{
SqlCore sqlCore = new SqlCore();
return sqlCore.getUserLogs();
}

現在用戶端調用WCF服務中的方法:

View Code

protected override void OnNavigatedTo(NavigationEventArgs e)
{
SeAdminSvc.SeAdminClient client = new SeAdminSvc.SeAdminClient();
client.getLogsCompleted+=new EventHandler<SeAdminSvc.getLogsCompletedEventArgs>(client_getLogsCompleted);
client.getLogsAsync();
}
private void client_getLogsCompleted(object sender, SeAdminSvc.getLogsCompletedEventArgs e)
{
dataGrid.ItemsSource = null;
dataGrid.AutoGenerateColumns = true;
dataGrid.ItemsSource = e.Result;
}

編譯後運行程式,將會收到一個異常:  “e.Result”引發了“System.Reflection.TargetInvocationException”類型的異常

其實這就是由於自訂枚舉類型導致的,如果將自訂枚舉類型換成String類型,問題便可迎刃而解。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.