注册 | 登录

c# - Connect Windows Store Apps to SQL Server Database Using WCF

itPublisher 分享于



推荐:将SQL server迁移到Windows Azure上的SQL database

Windows Azure把SQL作为服务提供给了用户,这项服务名为SQL database。尽管SQL database的后台也是SQL server,但是它与SQL server还是有很多的不同,具体体现在

Hello I am trying to connect the Windows store app to the SQL server database using the WCF as a middle-ware. I was able to do it successfully. But I am not able to insert the valuses into the database. Please anyone can help me with this?

Here is my code:

This is MainPage.xaml


    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" RenderTransformOrigin="0.508,0.484">
        <TextBox HorizontalAlignment="Left" Name="IdTextbox" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="108,162,0,0" Width="246"/>
        <TextBox HorizontalAlignment="Left" Name="NameTextbox" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="762,162,0,0" Width="246"/>
        <TextBox HorizontalAlignment="Left" Name="AgeTextBox"  TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="762,314,0,0" Width="246"/>
        <TextBox HorizontalAlignment="Left" Name="GenderTextBox"  TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="108,314,0,0" Width="246"/>
        <TextBox HorizontalAlignment="Left" Name="EmailTextBox"  TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="762,241,0,0" Width="246"/>
        <TextBox HorizontalAlignment="Left" Name="PasswordTextBox"  TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="108,241,0,0" Width="246"/>
        <Button Content="ShowData" Name="ShowData" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="590,422,0,0" Click="ShowData_Click"/>
        <Button Content="InsertData" Name="InsertData" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="352,422,0,0" Click="InsertData_Click"/>
        <GridView HorizontalAlignment="Left" Name="EmpGridview"  VerticalAlignment="Top" Width="150" Margin="646,162,0,0" Grid.Column="1" />


This is MainPage.xaml.cs:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Popups;

namespace WindowsStoreToSql
    public sealed partial class MainPage : Page
        App2.ServiceReference1.Service1Client MyService;
        public MainPage()
        protected override void OnNavigatedTo(NavigationEventArgs e)
            MyService = new App2.ServiceReference1.Service1Client();
        private async void InsertData_Click(object sender, RoutedEventArgs e)
            await MyService.InsertEmployeeAsync(new App2.ServiceReference1.Employee() {EmpId = Convert.ToInt32(IdTextbox.Text), EmpName = NameTextbox.Text, EmpAge = AgeTextBox.Text, EmpGender = GenderTextBox.Text, EmpEmail = EmailTextBox.Text, EmpPassword = PasswordTextBox.Text });
        private async void ShowData_Click(object sender, RoutedEventArgs e)
            var EmpList = await MyService.GetEmployeeAsync();
            foreach (var Emp in EmpList)
                GridViewItem EmpView = new GridViewItem();
                StackPanel Spanel = new StackPanel();
                Spanel.Children.Add(new TextBlock() { Text = Convert.ToString(Emp.EmpId) });
                Spanel.Children.Add(new TextBox() { Text = Emp.EmpName });
                Spanel.Children.Add(new TextBlock() { Text = Emp.EmpAge });
                Spanel.Children.Add(new TextBlock() { Text = Emp.EmpGender });
                Spanel.Children.Add(new TextBox() { Text = Emp.EmpEmail });
                Spanel.Children.Add(new TextBlock() { Text = Emp.EmpPassword });
                EmpView.Content = Spanel;

My problem:

At the line:

推荐:csharp: SQL Server 2005 Database Backup and Restore using C#

1.第一种方式: using SQLDMO;//Microsoft SQLDMO Object Library 8.0 /// <summary> /// 数据库的备份 /// 涂聚文注:数据库的备份和实时进度

await MyService.InsertEmployeeAsync(new App2.ServiceReference1.Employee() { EmpId = Convert.ToInt32(IdTextbox.Text), EmpName = NameTextbox.Text, EmpAge = AgeTextBox.Text, EmpGender = GenderTextBox.Text, EmpEmail = EmailTextBox.Text, EmpPassword = PasswordTextBox.Text });

I am getting an EndpointNotFound Exception :

> There was no endpoint listening at
> http://localhostname/Design_Time_Addresses/WcfServiceLibrary1/Service1/
> that could accept the message. This is often caused by an incorrect
> address or SOAP action. See InnerException, if present, for more
> details.

I am not able to resolve this. Can anyone please help me with this?

Thank you.

c# sql-server wcf
  this question
asked Oct 6 '13 at 16:04 Niveda Kalaiselvan 6 3      I think you should also include the code of your Web.Config (WCF) because the problem might be coming from it –  fattikus Oct 6 '13 at 16:11      I am asking you to add the web.config of your webservice because you might need to add something like this: <endpoint address="" binding="basicHttpsBinding" contract="Service.ServiceName" /> –  fattikus Oct 6 '13 at 16:14      Too much code. Please trim all the code which is not relevant to your question. –  tom redfern Oct 7 '13 at 7:22


Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

推荐:如何在Windows Azure VM上的SQL Server和Windows Azure SQL Database两者中做出选择

作者信息:本篇文章是由SQL Server Cloud Infrastructure Team的 Madhan Arumugam 和 Guy Bowerman共同著作。 简介 把SQL 数据托管在哪里,Windows Azure 为您提








您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱