2008/10/24

C# WebService Client 設定

開發環境為 Visual Studio 2008
設定完成後會有一個 MasterService 類別,使用這個類別的 Service 就可對 WebService 的各個方法進行存取了。

MasterService.Service service = new MasterService.Service();
service.XXXWebMethod();


點選左下角的 Advanced... 按鈕

點選左下角的 Add Web References ...

輸入 URL: http://www.diija.com.tw/API/MasterService.asmx, 注意:不用加上 ?WSDL"

crossdomain 設定

須取名為 crossdomain.xml,並放在網站上的根目錄
http://www.diija.com.tw/crossdomain.xml

*.2kuso.com : wildcard 設定,www.2kuso.com, ww2.2kuso.com 都符合規則,因此會套用。
domain 可以設為 ip 格式, domain="140.119.182.100"
headers="SOAPAction", 有些瀏覽器(IE)如果沒有設 SOAPAction 會無法取得 WebService 的回傳內容。


<?xml version="1.0"?>

<!DOCTYPE cross-domain-policy SYSTEM
"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>
<!-- secure = false, means allow https access -->
<allow-access-from domain="*.2kuso.com" secure="false" />

<allow-access-from domain="*.diija.com" secure="false" />
<allow-access-from domain="*.diija.com.tw" secure="false" />

<allow-access-from domain="140.119.182.100" secure="false" />

<allow-http-request-headers-from domain="*.2kuso.com" headers="SOAPAction"/>

<allow-http-request-headers-from domain="*.diija.com" headers="SOAPAction"/>
<allow-http-request-headers-from domain="*.diija.com.tw" headers="SOAPAction"/>

<allow-http-request-headers-from domain="140.119.182.100" headers="SOAPAction"/>
</cross-domain-policy>


2008/10/23

VirtualBox NAT forword 設定

注意,在 Guest 裡 NAT 設定是 ping 不到主機的。

#CentOS-5.2 為 Guest 名稱。
如果改壞了設定,可以到 $HOME/.VirtualBox\Machines\CentOS-5.2\CentOS-5.2.xml 修改。
改完必須重新啟動 VirtualBox 才會生效。

<ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" value="TCP"/>
<ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" value="22"/>
<ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" value="22"/>



##pcnet/0 是掛載的第一張網路配接卡, 1 是第二張,依此類推。
## ssh 是 key
Protocol, HostPort, Guest 必須對應到同一個 key, 這個 key 可以是任何合法字串。

#SSH TCP 標定
C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP

#從 Host Port 22 轉到 Guest Port 22
C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 22

C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22






#HTTP TCP 標定
C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/Protocol" TCP



#從 Host Port 22 轉到 Guest Port 22

C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/HostPort" 80



C:\Program Files\Sun\xVM VirtualBox>
VBoxManage setextradata "CentOS-5.2" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache/GuestPort" 80

Flex 取得某範圍亂數

程式function 如下:


public function GetRangeRandom(min:Number,max:Number):Number
{
return Math.round(Math.random()*(max-min))+min;
}

ex.我要如何取得 10 到 100的亂數 即可以呼叫

GetRangeRandom(10,100) ;


有沒有很溫馨..因為不知道AS Lib有沒有懶得查..

2008/10/22

C# PNG 轉 JPG 會變黑的問題

參考程式碼:

Image img = Image.FromFile(@"c:\source.png", true);

Bitmap bmp = new Bitmap(img );

Graphics graf = Graphics.FromImage(bmp);

graf.Clear(Color.White);

graf.DrawImage(img, 0, 0, img.Width, img.Height);

bmp.Save(@"c:\source.jpg", ImageFormat.Jpeg);



有沒有很溫馨