0
我已經嘗試修復代碼將從SQL數據庫得到蔚藍的推廣數據(表名是促銷是由ID的,PromoName,...等)連接Azure在UWP
我米嘗試使用WCF服務通過創建這些代碼
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
ObservableCollection<PromotionList> GetPromotionList();
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
這對Service1.svc.cs
public ObservableCollection<PromotionList> GetPromotionList()
{
ObservableCollection<PromotionList> result = new ObservableCollection<PromotionList>();
//Add data string here
SqlConnection conn = new SqlConnection();
try
{
conn.ConnectionString = //This one is ado one that copy from the azure
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
//Query Here
String cmdText = "Select * from Promo";
cmd.CommandText = cmdText;
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
result.Add(new PromotionList(){id=dr.GetInt32(0),PromoName=dr.GetString(1)});
}
}
catch(Exception)
{
throw;
}
finally
{
if(conn.State==ConnectionState.Closed)
{
conn.Close();
}
}
return result;
}
真正在宣傳片表中的數據進行有更詳細,但我選擇只有2
public class PromotionList
{
public int id { get; set; }
public string PromoName { get; set; }
}
我使用這項服務來我的主要應用程序的服務引用,並調用它
(In method public sealed partial class MainPage : Page)
public ObservableCollection<Connector.PromotionList> PromoList { get; set; }
....
(In method public MainPage())
PromoList = new ObservableCollection<Connector.PromotionList>();
....
(In method When the button is click)
Connector.Service1Client client = new Service1Client();
PromoList = client.GetPromotionListAsync().Result;
Debug.WriteLine(PromoList[0].PromoName);
它不會例外作品「名‘InnerExceptionCount’並不在當前的背景下存在」
我想知道這是爲什麼發生異常,以及如何解決它
謝謝
如果您的客戶端應用程序或Web服務發生異常,您可以共享嗎? – Daredevil
當我在設備上運行應用程序時,它在「PromoList = client.GetPromotionListAsync()。」結果;「 –