2011年6月8日 星期三
2011年5月16日 星期一
在VS2010 SP1專案中使用IIS 7.5 Express
Visual Studio 2010中使用File System方式建立Web Site或透過專案方式建立Web Application預設都會使用ASP.NET Development Server來執行網站程式,它相當於IIS 6.0的精簡版。若要使用到IIS 7.5的新功能,現在除了將網站建立在真正IIS 7.5上,還有另一個選擇,便是使用IIS 7.5 Express版。
首先你需要先到http://www.microsoft.com/web/gallery/install.aspx?appid=iisexpress下載IIS 7.5 Express,然後安裝:

安裝畫面;

完成後可以選擇安裝其它額外的功能。

以後在Visual Studio 2010 建立Web Site或Web Application時就可以選取要使用IIS 7.5 Express來執行;

Visual Studio會詢問是否要使用IIS 7.5 Express;

然後轉換

以後在工作列下方就可以看到IIS Express的小圖示,

在Visual Studio 2010專案屬性視窗下方也可以進階去設定驗證方式,要不要使用SSL等等功能

你也可以在Visual Studio 2010 的Tools->Options中設定未來的網站程式,會優先使用IIS 7.5 Express來執行
首先你需要先到http://www.microsoft.com/web/gallery/install.aspx?appid=iisexpress下載IIS 7.5 Express,然後安裝:
安裝畫面;
完成後可以選擇安裝其它額外的功能。
以後在Visual Studio 2010 建立Web Site或Web Application時就可以選取要使用IIS 7.5 Express來執行;
Visual Studio會詢問是否要使用IIS 7.5 Express;
然後轉換
以後在工作列下方就可以看到IIS Express的小圖示,
在Visual Studio 2010專案屬性視窗下方也可以進階去設定驗證方式,要不要使用SSL等等功能
你也可以在Visual Studio 2010 的Tools->Options中設定未來的網站程式,會優先使用IIS 7.5 Express來執行
2011年4月19日 星期二
Q&A 從WCF回傳ArrayList與自訂型別
收到李先生問題如下:
Q :
我的 WCF Service 需回傳 ArrayList,
若 ArrayList 只內含一些 string, 程式可 work,
但 ArrayList 若內含一些 Custom Class 就不 work,
請問老師問題出在那兒 ?
A:
善用DataContract與ServiceKnownType Attribute就可以囉~
例如Service Contract為:

Client
Q :
我的 WCF Service 需回傳 ArrayList,
若 ArrayList 只內含一些 string, 程式可 work,
但 ArrayList 若內含一些 Custom Class 就不 work,
請問老師問題出在那兒 ?
A:
善用DataContract與ServiceKnownType Attribute就可以囉~
例如Service Contract為:
[ServiceContract]
public interface IService {
[OperationContract]
[ServiceKnownType ( typeof ( CompositeType ) )] ArrayList GetData ( );
}
[DataContract] public class CompositeType {
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue {
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue {
get { return stringValue; }
set { stringValue = value; }
}
}
服務:public interface IService {
[OperationContract]
[ServiceKnownType ( typeof ( CompositeType ) )] ArrayList GetData ( );
}
[DataContract] public class CompositeType {
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue {
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue {
get { return stringValue; }
set { stringValue = value; }
}
}
public class Service : IService {
public ArrayList GetData ( ) {
ArrayList ar = new ArrayList ( );
CompositeType c = new CompositeType ( );
c.StringValue = "aaa";
ar.Add ( c );
return ar;
}
}
產生Proxy 時要設public ArrayList GetData ( ) {
ArrayList ar = new ArrayList ( );
CompositeType c = new CompositeType ( );
c.StringValue = "aaa";
ar.Add ( c );
return ar;
}
}
Client
ServiceReference1.ServiceClient c = new ServiceReference1.ServiceClient ( );
ArrayList ar = ( ArrayList ) c.GetData ( );
Console.WriteLine ( (( CompositeType ) ar [ 0 ]).StringValue.ToString() );
ArrayList ar = ( ArrayList ) c.GetData ( );
Console.WriteLine ( (( CompositeType ) ar [ 0 ]).StringValue.ToString() );
2011年3月30日 星期三
WPF資料繫結-DataContext
若有一WPF視窗包含以下XAML,Grid包含三個控制項TextBox、Label與TextBlock
<Grid x:Name="grid1">
<TextBox Height="23" HorizontalAlignment="Left" Margin="34,26,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="34,68,0,0" Name="label2" VerticalAlignment="Top" Width="132" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="34,0,0,127" Name="textBlock1" Text="TextBlock" VerticalAlignment="Bottom" Width="125" />
</Grid>
如果為這三個控制項的屬性設定資料繫時都指定了相同的Source,那麼就代表Source要設三次,後續要更改Source時,就得改三遍。如果多個資料繫結共用了相同的Source,您可以使用DataContext來簡化設計。在WPF中每一個繼承自FrameworkElement的類別都有DataContext屬性。<TextBox Height="23" HorizontalAlignment="Left" Margin="34,26,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="34,68,0,0" Name="label2" VerticalAlignment="Top" Width="132" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="34,0,0,127" Name="textBlock1" Text="TextBlock" VerticalAlignment="Bottom" Width="125" />
</Grid>
利用Expression Blend 4,選取畫面上的Grid,從屬性視窗點選DataContext後方的「New」按鈕。
選取要繫結的自訂物件,以MyDataClass2為例:
Code:
public class MyDataClass2 : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
private string _MyProperty="";
public string MyProperty {
get { return _MyProperty; }
set {
if ( _MyProperty != value ) {
_MyProperty = value;
PropertyChanged ( this , new PropertyChangedEventArgs ( "MyProperty" ) );
}
}
}
}
回到設計畫面,點選Label控制項Context屬性後方的Advanced Properties->Data Binding->選取要繫結到MyDataClass2的MyProperty。public event PropertyChangedEventHandler PropertyChanged;
private string _MyProperty="";
public string MyProperty {
get { return _MyProperty; }
set {
if ( _MyProperty != value ) {
_MyProperty = value;
PropertyChanged ( this , new PropertyChangedEventArgs ( "MyProperty" ) );
}
}
}
}
按照相同的步驟為TextBlock和TextBox控制項的Text屬性進行相同的資料繫結設定。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:wpfDataBinding" x:Class="wpfDataBinding._7_DataContext"
Title="_7_DataContext" Height="300" Width="300">
<Grid x:Name="grid1">
<Grid.DataContext>
<local:MyDataClass2/>
</Grid.DataContext>
<TextBox Height="23" HorizontalAlignment="Left" Margin="34,26,0,0" x:Name="textBox1" VerticalAlignment="Top" Width="120" />
<Label Content="{Binding MyProperty}" Height="28" HorizontalAlignment="Left" Margin="34,68,0,0" x:Name="label2" VerticalAlignment="Top" Width="132" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="34,0,0,127" x:Name="textBlock1" Text="{Binding MyProperty}" VerticalAlignment="Bottom" Width="125" />
</Grid>
</Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:wpfDataBinding" x:Class="wpfDataBinding._7_DataContext"
Title="_7_DataContext" Height="300" Width="300">
<Grid x:Name="grid1">
<Grid.DataContext>
<local:MyDataClass2/>
</Grid.DataContext>
<TextBox Height="23" HorizontalAlignment="Left" Margin="34,26,0,0" x:Name="textBox1" VerticalAlignment="Top" Width="120" />
<Label Content="{Binding MyProperty}" Height="28" HorizontalAlignment="Left" Margin="34,68,0,0" x:Name="label2" VerticalAlignment="Top" Width="132" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="34,0,0,127" x:Name="textBlock1" Text="{Binding MyProperty}" VerticalAlignment="Bottom" Width="125" />
</Grid>
</Window>
2011年3月9日 星期三
WPF UI Localization
訂閱:
文章 (Atom)