Need Help reading WKB

Editor
Jun 24, 2010 at 12:28 PM
Edited Jun 30, 2010 at 5:40 PM

Hi ,

can you help me with reading and visualizing wkb data from my sql server 2008 ? Hi really don´t know if its the right approach, but you can have a look at my code. It´s not completed, perhaps you can help me to do it. I want to read and save data via a wcf.

The WCF

ServiceContract(Namespace = "")] public class WKB_Service
{
[OperationContract]
public byte[] GetData(int id)
{
string query = "SELECT [ID],[GEN],[geom],geom.STAsBinary() as WKB FROM [VG_Geodaten_geography].[dbo].[vg250_bld] WHERE ID=@ID";
const string connectionString = "Server = Area51\\SPATIAL_R2;Database=VG_Geodaten;Trusted_Connection=True;";
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.AddWithValue("@ID", id.ToString());
using (SqlDataReader reader = cmd.ExecuteReader())
 {
while (reader.Read())
 {
return reader.GetSqlBytes(0).Value; }
 reader.Close();
 }
}
conn.Close(); } } catch (Exception e) { MessageBox.Show(e.Message); } return null; } } }

 

 

Silverlight Client

Then I created a service reference:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Maps.MapControl;
using System.ServiceModel;
using System.Runtime.Serialization;
using Demo_WKB.WKBServiceReference;
using System.Collections.ObjectModel;
using System.Windows.Browser;
using GisSharpBlog.NetTopologySuite.Geometries;


namespace Demo_WKB


{
public partial class MainPage : UserControl
{
private WKB_ServiceClient wkbsvc;
public MainPage()
{
InitializeComponent();
wkbsvc = GetServiceClient();
}

private WKB_ServiceClient GetServiceClient()
{
Uri uri = new Uri(HtmlPage.Document.DocumentUri, "WKB_Service");
EndpointAddress address = new EndpointAddress(uri);
return new WKB_ServiceClient("*", address);
}
private void checkBox_clicked(object sender, RoutedEventArgs e)
{
CheckBox cb = sender as CheckBox;
switch (cb.Content.ToString())
{
case "Bld":
{
if((bool) cb.IsChecked)
{
wkbsvc.GetDataCompleted += wkbsvc_GetDataCompleted;
wkbsvc.GetDataAsync(1);
}
else
{
(MyMap.FindName("Bld") as MapLayer).Children.Clear();
}
break;
}
}
}

private void wkbsvc_GetDataCompleted(object sender, GetDataCompletedEventArgs e)
{
// WHAT TO DO HERE ???
// I want to load the features in my BLD MapLayer
// so i need a foreach loop ?
}
}
}

 

It would be great if you could help me.

thank you!

regards