嘗試RemotingSqlHelper的若干問題

2022-03-02 10:18:11 字數 3696 閱讀 5993

some issues in remotingsqlhelper class

本來準備以

microsoft

提供的sqlhelper class

為基礎,改寫成基於

.net remoting

版本的資料訪問類

remotingsqlhelper

。整個過程出現了不少異常,也了解到使用

.net remoting

過程中需要注意的若干問題。

btw,如果對上述議題不清楚,可以參考下面的鏈結

reference 1:

將sqlhelper class部署為remote object可行嗎?

下面按照整個過程的步驟,針對這些問題進行簡要分析:(1

)改寫sqlhelper

和sqlhelperparametercache

類,刪除

static

關鍵字,然後相應修改內部的方法,這步比較簡單。並建立

web.config

配置檔案,進一步測試

remotingsqlhelper

成功部署在

iis中(可以參考《如何檢測remote objects是否部署成功

》)。(2

)使用soapsuds

生成remotingsqlhelper

類的元資料(

metadata

),這裡發現了乙個問題:

remotingsqlhelper class

中帶有params

引數的方法在

soapsuds

產生的元資料中丟失了

params

關鍵字。

如下remotingsqlhelper

方法:publicint executenonquery(string connectionstring, commandtype commandtype, string commandtext, params sqlparameter commandparameters)

在生成的元資料中變為(丟失了

params

):publicint executenonquery(string connectionstring, commandtype commandtype, string commandtext, sqlparameter commandparameters)

只好通過

soapsuds

的-gc

選項生成

source code

,然後手工編輯產生的檔案。

ok,這個問題就這樣解決了。(3

)修改client

端,這步也比較簡單。

先建立client

端configuration

配置檔案,然後在

client

端引用remote objects。(

4)開始正式除錯

client

端,各種異常及其分析登場了。(i

)an unhandled exception of type 'system.runtime.remoting.remotingexception' occurred in mscorlib.dll

第乙個異常資訊顯示

remoting proxy

沒有通道接收器(

channel sink

),或者

server

端沒有註冊監聽的

server

通道,或者

client

端沒有合適的通道與

server

通話。其實,就是

server

端**client

,沒有client

端的通道資訊。只要在

client

端configuration

檔案進行如下設定:

上述異常就不出現了。(ii

)an unhandled exception of type 'system.runtime.remoting.remotingexception' occurred in mscorlib.dll

additional information: permission denied: cannot call non-public or static methods remotely.

馬上第二個異常資訊出現了,顯示拒絕訪問:不能遠端呼叫非

pulic

或static

方法。為什麼會出現這個問題呢?看看下面這個方法:

publicint executenonquery(sqlconnection connection, commandtype commandtype, string commandtext, params sqlparameter commandparameters)

client

端在呼叫上述

remote method

時,需要傳入

sqlconnection

和sqlparameter

物件,sqlconnection

和sqlparameter

都是marshalbyrefobject

物件,這樣僅僅只有

client

端物件引用(

a reference to the client object

)傳遞到

server

端,而不是實際的物件。因此,在

server

端執行上述

remote method

時,需要**

client

的上述物件(現在知道為什麼異常

1會出現了吧!),而

server

沒有許可權呼叫

client

端的物件,就丟擲

exception了。以

sqlhelper class

中executenonquery()

方法為例,

executenonquery()

方法共有

9個過載,適合

client

端以remoting

方法呼叫的,僅僅只有乙個:

executenonquery(string connectionstring, commandtype commandtype, string commandtext)

sqlhelper class

中令人嚮往的呼叫

stored procedure

,並傳入

sqlparameter

引數的方法在這裡就無法使用了,這一點比較遺憾。不過,仍可以通過在

business rules

層拼接sql script

指令呼叫

stored procedure

並呼叫上述方法來完成,顯然**的可讀性及維護性就比較差了。

.net remoting

reference:

1, rickie,

將sqlhelper class部署為remote object可行嗎?

2, rickie,

如何檢測remote objects是否部署成功

嘗試著說,嘗試著做

成長,需要磨練 生活,需要經歷 習慣,需要堅持。心裡有什麼,說出來 想什麼,寫出來 要什麼,做出來。很多東西,如果自己不去說,不去做。就真的成為自己的東西了,成為爛在自己心裡的東西了。如果自己不知道自己想做什麼,會做什麼,就嘗試著去想,嘗試著去做,不能讓自己在混沌中屏跡。如果自己沒有自己的心聲,就嘗...

分治嘗試A

簡單的分治 平面上最近點對 description 給定平面上n個點,找出其中的一對點的距離,使得這n個點的所有點對中,該距離為所有點對中最小的。input 第一行 n 2 n 60000 接下來n行 每行兩個整數 x y,表示乙個點的行座標和列座標,中間用乙個空格隔開。output 僅一行,乙個實...

嘗試ruby程式設計

1.安裝好ruby1.8.7 在命令列中ruby v 顯示版本號,就說明ruby已經安裝好了。雙擊路徑下的irb.bat檔案,進入命令視窗,進行互動式ruby 2.簡單用法 1 puts puts hello world 回車 hello world puts 1 3 4puts 2 3 6 2 d...