2010/07/05

MSMQ 歷險記

 

MSMQ Overview

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

Message Queuing (MSMQ) 學習心得分享

http://blog.miniasp.com/post/2010/04/MSMQ-Message-Queuing-Learning-Notes.aspx

 

 

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

MSMQ 3.0 too secure for you?

http://blogs.msdn.com/b/johnbreakwell/archive/2007/01/15/msmq-3-0-too-secure-for-you.aspx

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

Message Queuing security overview

http://technet.microsoft.com/en-us/library/cc759412%28WS.10%29.aspx

這邊有一個 step by step

http://jwbs-blog.blogspot.com/2009/06/msmq-continued.html

 

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

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

*是否有開啟 MSMQ Service ?

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

PUBLIC=QueueGUID
DIRECT=Protocol:ComputerAddress\QueueName
DIRECT=OS:ComputerName\private$\QueueName
PRIVATE=ComputerGUID\QueueNumber

OR
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

http://www.infosysblogs.com/microsoft/2007/02/msmq_sending_message_to_remote.html

MSMQ - Receiving messages from remote private queues

http://www.infosysblogs.com/microsoft/2007/05/msmq_receiving_messages_from_r.html

 

如何取得 Outgoing Queues

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

 

 

如何取得 Queue 裡的訊息數

 

其他

MessageQueueErrorCode.cs 錯誤代碼對照

http://www.koders.com/csharp/fidE632059BF610D9D912C019A96DCF7A2DD76C847F.aspx

MessageQueueErrorCode Enumeration(MSDN)

http://msdn.microsoft.com/en-us/library/system.messaging.messagequeueerrorcode%28VS.80%29.aspx

2010/05/12

IIS Basic Authentication & Windows Authentication Slow Issue

最近遇到的問題是這樣子的:

 

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

 

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

 

擷取http://www.iis.net/ConfigReference/system.webServer/security/authentication/basicAuthentication片段如下:

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 好多了。

image

 

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

Basic

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 檢查名稱的部份

image

 

 

Basic

http://www.iis.net/ConfigReference/system.webServer/security/authentication/basicAuthentication

Widnows

http://www.iis.net/ConfigReference/system.webServer/security/authentication/windowsAuthentication

2010/04/26

iPhone 開發 Web 應用程式小技巧

1.特殊連結

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

3.版面調整

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" />

 

4.強制不偵測電話號碼

<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); }
</script>  

 

 

 

 

相關連結

Safari Dev Center

http://developer.apple.com/safari/

iPhone Development: 12 Tips To Get You Started

http://articles.sitepoint.com/article/iphone-development-12-tips

Sarafi HTML Ref

http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariHTMLRef/Introduction.html

Sarafi HTML Ref - PDF Version

http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariHTMLRef/SafariHTMLRef.pdf

Sarafi User Guide Ref

http://developer.apple.com/safari/library/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/1Introduction/Introduction.html

Sarafi User Guide Ref - PDF Version

http://developer.apple.com/safari/library/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/Safari_Developer_Guide.pdf

 

 

 

 

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

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

 

image

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)";
}
else

之下增加

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

else

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

image

2010/04/23

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.

A:http://msdn.microsoft.com/en-us/library/aa355056.aspx

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

WCF Client Avoiding Problems with the Using Statement

Aa355056.note(en-us,VS.100).gifNote:

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 排除

http://msdn.microsoft.com/zh-tw/library/system.runtime.serialization.datacontractattribute%28VS.90%29.aspx

=====

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

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

=====

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

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

範例:

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

Sharing Enum with WCF Service

2010/04/16

KB-Report Viewer Control Localization

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

Microsoft Report Viewer 2008 SP1 Redistributable

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=bb196d5d-76c2-4a0e-9458-267d22b6aac6

結果報表呈現上就是英文

image

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

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

http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID=c1df3b07-09d7-48cb-bb63-df6d3c2f8141

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

http://www.microsoft.com/downloads/details.aspx?familyid=C1DF3B07-09D7-48CB-BB63-DF6D3C2F8141&displaylang=zh-tw

image

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

1.Page

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

2.Web.config

<System.Web>

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

</System.Web>

 

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

Microsoft Report Viewer 2008 SP1 Redistributable - 繁體中文

http://www.microsoft.com/downloads/details.aspx?familyid=BB196D5D-76C2-4A0E-9458-267D22B6AAC6&displaylang=zh-tw

2010/01/13

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 結果建立暫存資料表

CREATE TABLE myTemp as

Select * from v_myView;

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

INSERT INTO myRemoteTable@remoteDB

select * from myTemp;

--卸除暫存資料表

DROP TABLE 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: 
============= 
DBLINK SEQUENCE GLOBAL_NAMES  ORA-2069
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. 
--OR--
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.