MSMQ 歷險記


MSMQ Overview

保哥的心得分享,深入淺出的介紹 MSMQ,並且許多有用的連結,推薦先看這一篇

Message Queuing (MSMQ) 學習心得分享




錯誤訊息:Access to Message Queuing system is denied

MSMQ 3.0 too secure for you?


小熊子測試的結果,上面的選項沒有用,跨 Domain 時,直接設定 Queue 安全性屬性 ANONYMOUS_LOGON=> Full Control

Message Queuing security overview


這邊有一個 step by step



錯誤訊息:The Message Queuing service is not available

*檢查防火牆是否有擋下 mqsvc.exe ?

*是否有開啟 MSMQ Service ?

*檢查 MSMQ 路徑格式是否有錯?


DIRECT=AddressSpecification\QueueName  (For public queues)
DIRECT=AddressSpecification\PRIVATE$\QueueName  (For private queues)
DIRECT=AddressSpecification\QueueName;JOURNAL  (For public queue journals)
DIRECT=AddressSpecification\PRIVATE$\QueueName;JOURNAL  (For private queue journals)
DIRECT=AddressSpecification\SYSTEM$;computersystemqueue  (Introduced in MSMQ 2.0 for the computer journal and dead-letter queues.)
DIRECT=URLAddressSpecification/QueueName  (Introduced in MSMQ 3.0)
(小熊子常常 OS:<ComputerName> 會寫成 OS:<IP> 當然會出錯!!)



如何遠端傳送 private Queue ?


MSMQ - Sending messages to remote private queues


MSMQ - Receiving messages from remote private queues



如何取得 Outgoing Queues

為什麼會需要檢查Outgoing Queue? MSMQ 在 Send Remote Queue 時,會先丟到本機的 Outgoing Queues,而且程式上不會出錯,但訊息有可能會卡在這個部份,所以需要程式化來做監控。



如何取得 Queue 裡的訊息數



MessageQueueErrorCode.cs 錯誤代碼對照


MessageQueueErrorCode Enumeration(MSDN)



IIS Basic Authentication & Windows Authentication Slow Issue



Basic 認證慢,Windows 認證快 (本機帳號認證快)


起先,看到 Basic Authentication 有一個 logonMethod 屬性可以設定



The logonMethod attribute can be one of the following possible values. The default is ClearText.

Value Description
Batch This logon type is intended for batch servers, where processes may be executing on behalf of a user without that user's direct intervention.

The numeric value is 1.
ClearText This logon type preserves the name and password in the authentication package, which allows the server to make connections to other network servers while impersonating the client.

The numeric value is 3.
Interactive This logon type is intended for users who will be using the computer interactively.

The numeric value is 0.
Network This logon type is intended for high performance servers to authenticate plaintext passwords. Credentials are not cached for this logon type.

The numeric value is 2.



IIS Program Manager Thomas Deml (http://blogs.iis.net/thomad) 在這篇有寫到

When you logon with Basic Authentication IIS caches the logon information (token) of a user in the IIS token cache. This is necessary because entering a single Url in the browser might generate hundreds of requests. Just look at some of your pages and count all the images and other HREFs you have in there. Each one is its own request. If IIS wouldn't cache the token it would have to call LogonUser for each one of these requests. This could result in going to the Domain Controller (which is probably on another machine) for each one of these request and this gets incredibly expensive and your web-site would get awfully slow.

These tokens are cached for 15 minutes by default. The timeout is completely configurable though. Have a look at the following article: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/6b2e7fcd-5fad-4ac8-ac0a-dcfbe771e9e1.mspx?mfr=true

The simplest way to purge the token cache is to recycle the Application Pool however or to call the FlushTokenCache API (search for FlushTokenCache).

Hope this helps.


下圖是 IIS7 Configuration Editor 設定 logonMethod 的方式,比起 IIS6 要另外安裝 Administrator Kit 好多了。



但是在 MSDN 上頭文件有說明:


IIS implements Basic authentication, which is part of the HTTP 1.0 specification, using Windows user accounts. When using Basic authentication, the browser prompts the user for a user name and password. This information is then transmitted across HTTP where it is encoded using Base64 encoding. Although most Web servers, proxy servers, and Web browsers support Basic authentication, it is inherently insecure. Because it is easy to decode Base64 encoded data, Basic authentication is essentially sending the password as plain text. For more information, see About Authentication in the IIS Documentation (http://www.microsoft.com/windows2000/en/server/iis/htm/core/iiabasc.htm).

The IIS metabase contains a LogonMethod property to specify the logon method for clear-text logons such as Basic authentication. By default, Basic authentication requires the Windows user account to have local logon rights at the Web server. If you use the default setting, IIS caches credentials during logon, which slows the logon process. By specifying either network logon or network with cleartext logon, IIS does not cache credentials at logon, which expedites the logon process. A local logon makes it possible for the user to access network resources, whereas a network logon does not. However, a network with cleartext logon makes it possible for the user to access network resources. For more information, see LogonMethod in the IIS Documentation (http://www.microsoft.com/windows2000/en/server/iis/htm/asp/apro1zms.htm).

To improve the security of this authentication scheme, you can use it in combination with Secure Sockets Layer/Transport Layer Security (SSL/TLS) support to encrypt the HTTP session. However, SSL/TLS impacts performance because it encrypts and decrypts all data on each exchange. TLS is the Internet Engineering Task Force (IETF) version of Netscape's SSL, sometimes referred to as SSL 3.1. For more information, see the specification (RFC 2246) on the Internet Engineering Task Force (IETF) Web site (http://www.ietf.org/rfc/rfc2246.txt).

When used in conjunction with Kerberos v5 authentication, IIS can delegate security credentials among computers running Windows 2000 and later that are trusted for delegation. Delegation enables remote access of resources on behalf of the delegated user.


老實說,我對於這些說法都被搞混了,後來我用了一個簡單的方式測試是否卡在 AD 認證:

將網域的人員加入本機群組,就可以發現有兩段會慢,第一段是下圖查詢 AD 的 Global Catalog,另一段是 Check Name 檢查名稱的部份









iPhone 開發 Web 應用程式小技巧


Google Map http://maps.google.com/maps?q=<地址>
電話 call:
簡訊 sms:
郵件 mailto:

2.iPhone 桌面上建立圖示

圖示大小:57 x 57px   

增加 <link rel="apple-touch-icon" href="<圖片網址>" />

例如 Hami.emome.net  http://hami.emome.net/img/hami_WebClip.png


Safari on iPhone 預設版型會以一般(桌上型)呈顯,但如果下了以下這行,會直接以 iPhone 寬度限制住(如 320px or 480px)

<meta name="viewport" content="width=device-width" />

預設縮放比例為 1

<meta name="viewport" content="initial-scale = 1.0" />

詳細 viewport 參考文件

<meta name="apple-mobile-web-app-status-bar-style" content="black" />



<meta name="format-detection" content="telephone=no">

5.隱藏網址列Hide address bar

<script type="text/javascript">
    if (navigator.userAgent.indexOf('iPhone') != -1) {
        addEventListener("load", function() {
            setTimeout(hideURLbar, 0);
        }, false);
    function hideURLbar() { window.scrollTo(0, 1); }






Safari Dev Center


iPhone Development: 12 Tips To Get You Started


Sarafi HTML Ref


Sarafi HTML Ref - PDF Version


Sarafi User Guide Ref


Sarafi User Guide Ref - PDF Version






如何讓 IE/Firefox/Chrome 可以模擬 iPhone 網頁?

安裝 Fiddler 後,透由 Customize Rules 變更 User-Agents 來進行模擬!!



public static RulesOption("IE &7 (Vista)", "&User-Agents", true)
var m_IE7: boolean = false;


public static RulesOption("IPHONE", "&User-Agents", true)
var m_IPHONE: boolean =false;


if (m_IE7){
    oSession.oRequest["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1)";


if (m_IPHONE){
    oSession.oRequest["User-Agent"] = "iPhone;Mozilla/4.0 (compatible; iphone;)";


存檔後關閉就會在下圖中出現 IPHONE



WCF 歷險記

WCF Test Client Tool

  • SOA Cleaner
    • 好用,但是不是免費
    • 支援 DataTable / DataSet
    • 不支援 maxBufferPoolSize , maxReceivedMessageSize
  • WCFTestClient.exe (Build in Visual Studio)
    • C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe
    • 不支援 DataTable / DataSet


Q:呼叫多次出現 cannot be used for communication because it is in the Faulted state.


Client 避免使用 Using 改用 Try...Catch...

WCF Client Avoiding Problems with the Using Statement


The using statement and ServiceHost: Many self-hosting applications do little more than host a service, and ServiceHost.Close rarely throws an exception, so such applications can safely use the using statement with ServiceHost. However, be aware that ServiceHost.Close can throw a CommunicationException, so if your application continues after closing the ServiceHost, you should avoid the using statement and follow the pattern previously given.


Q: WCF Proxy Class can not generated 無法自動產生 Service Reference?

A: 有可能含有 WCF 不支援的型別,例如 DateTime?
可以使用 DataContractAttribute 排除



Q:為什麼回傳 DataTable 會出現錯誤?

A:序列化時 DataTable.TableName 為必填欄位,要記得指定。


Q:為什麼無法回傳 Enum 型別?

A:需設定 [EnumMember] 在 Client 才會出現正確


public enum FuncRight { [EnumMember]Read, [EnumMember] Edit };

Sharing Enum with WCF Service


KB-Report Viewer Control Localization

最近 Web 使用了 Report View Control 來做為報表的呈顯,但是 Server 安裝版本是 English,無法呈顯多語系

Microsoft Report Viewer 2008 SP1 Redistributable




試了很久,後來發現 Report View 有 Language Pack

Microsoft Report Viewer Redistributable 2008 SP1 语言包-簡體中文


Microsoft 可轉散發報表檢視器 2008 SP1 語言套件-繁體中文



安裝後就可以依據 Browser 的語言來做切換,另外在 Server 上也可以定義:


<%@ Page Language="C#" ...... Culture="zh-tw" %>



         <globalization uiCulture="zh-tw" culture="zh-tw" />



比較方便的方法是直接安裝繁體中文版的 Report View ,就會內含繁中+英文。

Microsoft Report Viewer 2008 SP1 Redistributable - 繁體中文



ORA-02069: global_names parameter must be set to TRUE for this operation

最近在做正式台與測試台 Oracle 的資料轉檔,結果遇到這個錯誤

ORA-02069: global_names parameter must be set to TRUE for this operation

會遇到這個錯誤,小熊子初步分析是用 View 的結果轉入 DBLink 的遠端 Table 問題。



後來找到這麼一篇文章,我的解法是用暫存 table 轉入 DBLink 的遠端 Table 以下是範例:


--依 select 結果建立暫存資料表


Select * from v_myView;

--用暫存資料表轉入遠端 Table

INSERT INTO myRemoteTable@remoteDB

select * from myTemp;





Heres a note from Oracle that explains whats going on, and offers a bit of a clumsy workaround.

Problem Description: 
You receive an ORA-02069 error during an insert to a remote database through a 
database link when the insert contained a local sequence. 
    ORA-02069: global_names parameter must be set to TRUE for this operation 
        Cause: A remote mapping of the statement is required but cannot be 
               achieved because global_names should be set to TRUE for it to 
               be achieved. 
       Action: Issue alter session set global_names = true if possible 
Problem Explanation:
This is expected behaviour.
The insert statement is transformed so that it can be executed at the remote 
end of the dblink. The reference to the local sequence has to be qualified so 
that the remote end knows to call back to the local instance. The qualification
is made by appending @local_dbname.domain to the sequence reference if 
global_names=true. When global_names=false, the code cannot make the assumption
that the qualifier will be valid and reports the error ORA-02069 'global_names 
parameter must be set to TRUE for this operation'.
Search Words: 
Solution Description: 
Use the following workaround: 
1. Create a 'temporary' table on the local database for holding the inserts. 
2. Insert the entire row into this table. 
3. Insert the 'temporary' row from the temporary table to the remote table. 
4. Delete the 'temporary' row from the temporary table.

This is slower but it will get around the problem. 
Set GLOBAL_NAMES=TRUE in the init<SID>.ora
Solution Explanation:
The first workaround bypasses the remote node having to make a 
call back to the local instance to reference the local sequence.