1 웹콘피그 설정
wsHttpBinding 를 basicHttpBinding 변경
<service behaviorConfiguration="TESTSliverlight.Web.Service1Behavior"
name="TESTSliverlight.Web.Service1">
<endpoint address="" binding="basicHttpBinding" contract="TESTSliverlight.Web.IService1">
<!--
<endpoint address="" binding="wsHttpBinding" contract="TESTSliverlight.Web.IService1">
-->
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
2. wcf 웹서비스로 전달할 클래스 만들기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace TESTSliverlight.Web
{
[DataContract]
public class WCFBook
{
public WCFBook(string BookTitle) {
this.BookTitle = BookTitle;
}
[DataMember]
public string BookTitle { get; set; }
}
}
3.웹서비스 만들기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace TESTSliverlight.Web
{
// NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config.
public class Service1 : IService1
{
public void DoWork()
{
}
public List<WCFBook> GetBookData()
{
//하나의 값만 보내고 싶으면 return WCFBook 하면된다
//실버라이트에서 받을땐 e.result.BookTitle 이런씩으로 받으면 됩니다
List<WCFBook> li = new List<WCFBook>();
li.Add(new WCFBook("1111"));
li.Add(new WCFBook("2222"));
li.Add(new WCFBook("3333"));
return li;
}
}
}
실버라이트에서 처리하기
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 System.ServiceModel.Channels;
using System.ServiceModel;
using System.Collections.ObjectModel;
namespace TESTSliverlight
{
public partial class DataList : UserControl
{
ServiceBook.Service1Client sclient;
EndpointAddress defaultAddress;
public DataList()
{
InitializeComponent();
Binding defaultBinding = new System.ServiceModel.BasicHttpBinding();
defaultAddress = new System.ServiceModel.EndpointAddress("http://localhost:62711/Service1.svc");
sclient = new TESTSliverlight.ServiceBook.Service1Client(defaultBinding, defaultAddress);
sclient.GetBookDataCompleted += new EventHandler<TESTSliverlight.ServiceBook.GetBookDataCompletedEventArgs>(sclient_GetBookDataCompleted);
sclient.GetBookDataAsync();
}
void sclient_GetBookDataCompleted(object sender, TESTSliverlight.ServiceBook.GetBookDataCompletedEventArgs e)
{
this.ListWCF.ItemsSource = e.Result; //리스트 박스에 데이터 바인딩
}
}
}
-----------------------------------------------------------------------------------------------------------------------
<UserControl x:Class="TESTSliverlight.DataList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="440" Height="392" xmlns:TESTSliverlight="clr-namespace:TESTSliverlight"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:SB="clr-namespace:TESTSliverlight.ServiceBook">
<UserControl.Resources>
<SB:WCFBook x:Key="WCFBookDS" d:IsDataSource="True"/>
<DataTemplate x:Key="BookTitleTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=BookTitle}" />
<TextBlock Text="{Binding Path=BookTitle}" />
<TextBlock Text="{Binding Path=BookTitle}" />
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<TextBlock Height="48" HorizontalAlignment="Left" Margin="8,8,0,0" VerticalAlignment="Top" Width="192" Text="DATA LIST" TextWrapping="Wrap"/>
<ListBox Name="ListWCF" Margin="64,96,184,120" DataContext="{StaticResource WCFBookDS}"
ItemsSource="{Binding WCFBook}" ItemTemplate="{StaticResource BookTitleTemplate}"/>
</Grid>
</UserControl>
'C#.NET' 카테고리의 다른 글
| 'System.Data.Common.DataRecordInternal' 형식 개체를 'System.Data.DataRowView' 형식으로 캐스팅할 수 없습니다. (0) | 2009.12.02 |
|---|---|
| BackgroundWorker 클래스 (0) | 2009.12.02 |
| 쉐어포인트를 이용한 프로젝트 관리 (0) | 2009.12.01 |
| Windows Server 2008용 Windows Media 서비스 2008 (0) | 2009.12.01 |
| Ajax Toolkit 을 이용한 실시간 (페이지 전환없이) 파일업로드 구현하기 (2) | 2009.12.01 |
| (웹서비스 최소용량 해결방법)할당량을 늘리려면 적합한 바인딩 요소에서 MaxReceivedMessageSize 속성을 사용하십시오 (0) | 2009.12.01 |
| System.Data.SqlServerCe 오류해결방법 (0) | 2009.12.01 |
| 클릭원스를 이용한 dll 자동다운로드 (0) | 2009.11.30 |
| clientaccesspolicy.xml 파일을 사용하여 도메인 간 액세스를 허용하려면 (0) | 2009.11.30 |
| 실버라이트 웹서버에서 작동안될때(MIME 형식 설정) (0) | 2009.11.30 |