私は、AzureのSQLDatabaseからデータのリストを取得し、それをWindowsの汎用アプリケーションのリストビューにバインドしようとしています。その後、私のアプリケーションでこのサービスを呼び出すと、azureに公開します。UWPでデータベースからデータを取得する
現在のコードにはエラーがあります。 これはIService1.cs
namespace WcfService2
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
// TODO: Add your service operations here
[OperationContract]
List<NYPUnlocking> NYP_GetLockerStatus();
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class NYPUnlocking
{
[DataMember]
public int lockerID { get; set; }
[DataMember]
public string lockStatus { get; set; }
}
}
Service1.svc.csための私のコードです:私は、Azureの上でそれを公開し、自分のUWPのアプリケーション上の紺碧のウェブサイトにサービス参照を追加し
namespace WcfService2
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Service1 : IService1
{
public List<NYPUnlocking> NYP_GetLockerStatus()
{
SqlConnection conn = new SqlConnection("Copy ADO.net connection string");
string sqlStr = "SELECT * FROM dbo.lockerStatus";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
List<NYPUnlocking> ret = new List<NYPUnlocking>();
while (dr.Read())
{
NYPUnlocking unlock = new NYPUnlocking()
{
lockerID = Int32.Parse(dr["lockerID"].ToString()),
lockStatus = dr["lockStatus"].ToString()
};
ret.Add(unlock);
}
conn.Close();
return ret;
}
}
}
。以下のコードは私のXAMLとcsコードです。
私はxでエラーを持っている:データ型= "データ:NYPUnlocking"、「名前 "NYPUnlockingを使用して" 名前空間に存在しません "というエラー:。NYPUnlock.ServiceReference1" を
<Page.Resources>
<DataTemplate x:DataType="data:NYPUnlocking" x:Key="UserTemplate">
<StackPanel Orientation="Horizontal" Padding="0,0,0,0">
<TextBlock FontSize="12" Text="{x:Bind lockerID}" HorizontalAlignment="Left" Width="200" />
<TextBlock FontSize="12" Text="{x:Bind lockStatus}" HorizontalAlignment="Right" Width="200" />
</StackPanel>
</DataTemplate>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Width="354">
<ListView x:Name="lvLocker" ItemTemplate="{StaticResource UserTemplate}"/>
<TextBox x:Name="tbError" TextWrapping="Wrap" Text="Error"/>
</StackPanel>
</Grid>
そして、私のCSファイルには、私はすべてを正しくやっていると思う「暗黙のうちに 『NYPUnlock.ServiceReference1.NYPUnlocking []』
namespace NYPUnlock
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
getStatus();
}
public async void getStatus()
{
try
{
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(ServiceReference1.Service1Client.EndpointConfiguration.BasicHttpBinding_IService1);
var task1 = client.NYP_GetLockerStatusAsync();
ServiceReference1.NYPUnlocking[] returnResult = await task1;
lvLocker.ItemsSource = returnResult;
}
catch(Exception ex)
{
tbError.Text = ex.Message;
}
}
}
}
に型 『System.Collections.ObjectModel.ObservableCollection』を変換できませんと言ってTASK1待つでエラーをしています何が問題を引き起こしているのでしょうか?どのような助けも大変ありがとうございます!
あなたの早い返答をありがとう、私はあなたの最初の点を意味するものではありません。型をvarに変更すると問題は解決しますが、ありがとう! – NicholasKhongg