天天看點

跨域或者Internet通路Remoting[Remoting FAQ]

version

date

creator

description

1.0.0.1

2006-6-1

鄭昀@ultrapower

草稿

繼續閱讀之前,我們假設您熟悉以下知識:

n         remoting

雖然說,remoting一般都在同一個域内調用,但有時候,也需要跨域通路,甚至于跨internet通路。畢竟,讓第三方遠端測試下remoting方法,不能要求人家加入你的域。

在走tcp channel通路remoting情況下。

如果雙方未作特殊處理,那麼用戶端會得到如下異常,提示對方remoting服務不能信任你的身份:

異常資訊

unhandled exception:

system.security.authentication.invalidcredentialexception:

the server has rejected the client credentials.

---> system.componentmodel.win32exception: 登入沒有成功

by default, a tcp client channel authenticates itself with the user identity under which the client process is running. you can specify an alternative identity by setting theusedefaultcredentials configuration property to false and setting the domain, username, and password configuration properties to specify an alternative identity.

預設情況下,一個tcp客戶通道以目前運作的客戶程序之下的使用者辨別來驗證。也可以通過把usedefaultcredentials 配置屬性設為false 并且設定domain, username, and passwordconfiguration 配置屬性來設定特定的自定義辨別。

有人說,可以在服務端在注冊channel時,這麼做:

将原來的channelservices.registerchannel(chan1, true);

改為

channelservices.registerchannel(chan1, false);

如果是這樣聲明的:

remotingconfiguration.configure(filename, true);

remotingconfiguration.configure(filename, false);

這樣來允許另外一個域的機器通路。

       但是似乎沒有作用。

       下面這種做法,就不需要伺服器端作改動。用戶端調用時,需要知道伺服器端的一個普通使用者帳号密碼,來配置自己的remoting。

先看

用戶端的remoting配置資訊

<system.runtime.remoting>

    <application>

      <client>

        <wellknown type="xxxx,yyyy"

                   url="tcp://remotingserver:port/demo"/>

      </client>

      <channels>

        <channel ref="tcp" secure="true"   

                    impersonationlevel="impersonation" protectionlevel="encryptandsign"         

                    username="remotingserver-username" password="password"         

                    domain="remotingserver-domainname">

          <clientproviders>

            <formatter ref="binary"/>

          </clientproviders>

          <serverproviders>

            <formatter ref="soap" typefilterlevel="full" />

            <formatter ref="binary" typefilterlevel="full" />

          </serverproviders>

        </channel>

      </channels>

    </application>

  </system.runtime.remoting>

       用這樣的配置就可以成功模拟伺服器端的使用者調用remoting。

對于上面的配置資訊,我們需要說明幾個特别的節點:

client-settings

secure

true/false: enables/disables security

username, password, domain

if you don’t want to use the credentials of the client process, you can specify explicit ones here

impersonationlevel

identification: the server can use the client token only for identity information and role based checks 

impersonation: the server can impersonate the client token to access server-local resources

delegation: the server can delegate the client credentials

protectionlevel

none: clear text

encrypt/sign: self explanatory

encryptandsign: recommended setting

serviceprincipalname

spn of the server. required for kerberos. can use spn (service/domain) or account syntax (domain\service)

繼續閱讀