2011年7月27日 星期三

Expression Blend(16)- Path 基本繪圖

我們常會需要使用Pen工具來進行繪圖,以下是Pen工具基本操作。

  • 按P,選取工具箱上的Pen
  • 畫兩個點,按住第二個點拖曳,線條會變曲線

image

  • 連接開始點,會變封閉的Path

image

  • 按A切到Direct Selection,選任一點可以移動

image

  • Direct Selection,選任一線段可以移動此線段

image

  • 使用Pen在線上任意地方,可以增加點,或刪除點,增加的圖示

image

  • 刪除的圖示

image

  • Direct Selection,按CTRL可以選兩點以上,進行移動

image

  • Direct Selection,按ALT可以把尖銳的角轉變成圓角

image

  • Direct Selection,選任一線段再按ALT移動,此線段會有圓弧效果

image

  • Direct Selection,選任一線段再按Delete可以刪除線段

image

  • 加一個Image到畫面,將畫好的Path圖形移動到Image上方

image

  • Object->Path->Make Clipping Path

image

  • Image就根據Path自動剪裁

image

Expression Blend(15)- 3D Image與動畫(WPF)

你可以把一張圖片,或是3D模型加入Expression Blend之中,並加上動畫的效果。以下範例說明如何將圖片變成3D Image
這個範例只有WPF應用程式才可以使用。
  • 加一個Image到WPF應用程式
  • Make Image 3D
image
  • 原來的Image會變成Viewport3D
image
  • 我們可以使用工具箱上Camera Orbic工具使用拖曳的方式來變更圖片的3D顯示。使用滑鼠拖曳時可以按住ALT,進行前後移動。按住CTRL可以左右移動。
image
  • 左右移動
image
  • 上下移動
image
  • 旋轉
image

  • 建立動畫。先產生Storyboard
image
  • 按F6切換Expression Blend到動畫設計模式,按F6可以再切換回來
  • 黃色拉桿預設停在0秒。0秒時,將圖片移動到最左邊。
image
  • 移動黃色拉桿到1秒,接著將圖片移動到最右邊
image
  • 結束動畫錄製。
image
  • 按F5執行,你的3D圖片便會從左方飛到右方出現在視窗上。

Expression Blend(14)- Perspective Transforms

 

Perspective Transforms可以讓Silverlight項目有3度空間的效果(但非真的3D變形)。WPF不支援,只有Silverlight應用程式才支援。

  • 建立一個Silverlight應用程式
  • 加一個Image到XAML
  • 從屬性視窗可以看到Projection區段有一個Rotation頁,左方有一個圓型,其中有十字。

image

  • 利用滑鼠拖曳移動十字就可以轉換X、Y、Z軸。

image

  • 產生出的XAML參考如下

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="PerpectiveDemo.MainPage"
    Width="640" Height="480">

    <Grid x:Name="LayoutRoot" Background="White">
        <Image x:Name="___nEO_IMG_MP900407424_jpg"
        Margin="114,88,136,80" Source="/nEO_IMG_MP900407424.jpg" Stretch="Fill">
            <Image.Projection>
                <PlaneProjection RotationX="-47.445" RotationY="44.113"
                RotationZ="-34.144"/>
            </Image.Projection>
        </Image>
    </Grid>
</UserControl>

2011年7月26日 星期二

WCF教學(8) - 使用Windows Service裝載服務

實作服務並不能讓服務執行,你需要能接聽特定port的請求,並將請求傳給服務。WCF中的HOST可以接聽多個port,並視需求使用不同通訊類型。Host負責建立Endpoint,接聽請求,把請求傳到服務的operation。
以下步驟介紹如何建立Windows Service類型的程式來當作WCF Host裝載服務,並利用NetNamedPipeBinding和用戶端溝通。
  • File->New->Project,建立Windows Service專案,名稱 WindowsServiceHost
  • File->Add->New Project 加入WCF Service Library類型專案,名稱MyWCFService ,使用預設的服務介面和程式碼來完成這個練習。
  • WindowsServiceHost ,加入MyWCFService參考
image
  • WindowsServiceHost ,加入System.ServiceModel.dll參考
image
  • WindowsServiceHost ,Service1.cs,在OnStart方法啟動接聽,使用NetNamedPipeBinding
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
namespace WindowsServiceHost
{
    public partial class Service1 : ServiceBase
    {
        private ServiceHost myHost;        public Service1()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {
            myHost = new ServiceHost(typeof(MyWCFService.Service1));
            myHost.AddServiceEndpoint(typeof(MyWCFService.IService1),
                new NetNamedPipeBinding(),
                "net.pipe://localhost/complex"
                );
            myHost.Open();
        }
        protected override void OnStop()
        {
           myHost.Close();        }
    }
}



  • WindowsServiceHost ,加入Installer
image
  • WindowsServiceHost專案 ,ServiceInstaller1,StartType Property 設 Automatic
image
  • WindowsServiceHost 專案,ServiceProcessInstaller1,Account property 設 LocalSystem
image
  • WindowsServiceHost ,Build
  • 在Visual Studio 2010 Command Prompt安裝服務 ,執行 installutil WindowsServiceHost.exe
image
  • 在OS服務工具,Start the Service1
image
  • 加一個Console Application當Client,名稱ConClient
  • ConClient,Add Service Reference,產生proxy
image
  • ConClient,Edit app.config
image
  • ConClient,新增Client Endpoint
image
  • ConClient,設定呼叫資訊
image
  • ConClient,CTRL+S存檔,config檔看起來如下
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8732/Design_Time_Addresses/MyWCFService/Service1/"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="net.pipe://localhost/complex" binding="netNamedPipeBinding"
                bindingConfiguration="" contract="ServiceReference1.IService1"
                name="WinBinding" />
        </client>
    </system.serviceModel>
</configuration>
  • ConClient,修改Program.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConClient
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceReference1.IService1 proxy =
                new ServiceReference1.Service1Client("WinBinding");
            Console.WriteLine(proxy.GetData(10));
            Console.ReadLine();
        }
    }
}
  • 設ConClient為起始專案,因為裝載服務的WindowsServiceHost.exe已手動Run了
image
  • CTRL+F5執行,若跳出任何視窗,按yes,ConClient會印出You entered: 10,代表成功叫用服務



WCF教學(7) - 使用與修改預設端點

在WCF4你可以在不定義任何端點的情況下,裝載你的服務並定義基礎位址。Host會自動為服務建立端點,使用以下規則:
1.    Address:基礎位址。
2.    Binding:根據預設URI scheme的對應決定Binding類型。如”http” URI scheme則預設使用basicHttpBinding。
3.    Contract:根據定義服務合約的介面與實作的類別來決定,若服務實作了兩個合約,Host就會產生兩個端點。
我們透過範例來了解它。
  • New Web Site->WCF Service
image
  • File System
image
預設IService.cs檔案中定義一個介面
[ServiceContract]
public interface IService
{
    [OperationContract]
    string GetData(int value);
    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);
    // TODO: Add your service operations here
}
預設Service.cs檔案中Service類別實作了此介面
public class Service : IService
{
    public string GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }
//…略
}






  • Add ConClient到方案
image
image
  • ConClient->Add Service Reference
image
  • Discover
image

  • 檢視client config檔案預設使用basicHttpBinding
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:1160/MyWCFService/Service.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
                contract="ServiceReference1.IService" name="BasicHttpBinding_IService" />
        </client>
    </system.serviceModel>
</configuration>
  • 修改MyWCFService Web.Config檔案,改用wsHttpBinding
<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <protocolMapping>
      <add scheme="http" binding="wsHttpBinding"/>
    </protocolMapping>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

  • ConClient->Update Service Reference
image
  • 檢視client config檔案改用wsHttpBinding
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:1160/MyWCFService/Service.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
                contract="ServiceReference1.IService" name="WSHttpBinding_IService">
                <identity>
                    <userPrincipalName value="INSTRUCTOR\Administrator" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
  • Client Main,試著加入程式叫用服務
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConClient.ServiceReference1;
namespace ConClient
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceClient c = new ServiceClient();
            Console.WriteLine(c.GetData(10));
        }
    }
}

  • 設同時執行兩個專案
image
  • CTRL+F5執行,ConClient印出呼叫結果
image
  • 修改MyWCFService,改用Custom Binding,自訂
<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <protocolMapping>
      <add scheme="http" binding="customBinding"/>
    </protocolMapping>
    <bindings>
      <customBinding>
        <binding>
          <binaryMessageEncoding/>
          <httpTransport/>
        </binding>
      </customBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

  • ConClient Update Service Reference,ConClient也改用自訂的Custom Binding
  • CTRL+F5執行,ConClient印出呼叫結果


總網頁瀏覽量