Silverlight果然還是無法存取.NET Remoting

會有這個問題是因為先前有需要,也希望在Silvelight中看看能否存取.NET Remoting的遠端物件,不過當然,在當下每個人都知道Silverlight目前只支援3種資料存取方式:
  1. RIA Service
  2. WCF Data Service (之前稱為ADO.NET Data Service)
  3. WCF Service
不過筆者還是想要Try一下,當有一些不確定因素時筆者就是喜歡踹(是Try拉),行不行Try一下就知道,Try的過程當中也會有一些發現或是了解其原理,二話不說開始吧!
首先筆者記得.NET 3.0之後,因為新增了WCF,所以在Visual Studio 的IDE之中除了原先的加入 [加入參考] [加入Web參考] 之外,還多了 [加入服務參考],這是為了WCF服務而出現的,所以之後,像您現在如果使用如目前最新的visual Studio 2010的WinForm程式在加入服務參考的視窗下面還會有一個 [進階]按鈕,如下圖:
image
點選後,如下畫面:
image
畫面中還有一個加入Web參考的按鈕,在說明的地方也特別標註說這是相容於.NET Framework 2.0的。點選之後就是以前熟悉的Web 參考畫面如下:
image
而在Silverlight的專案中的[加入服務參考]的畫面中也沒有[加入Web參考]的按鈕,如下:
image
如果硬是在[加入服務參考]的地方輸入.NET Remoting公開的URL (Web Service/SOAP公開的方式),突然很高興的發現!!可以找的到一個服務ㄝ,還能夠分析的出有一個HelloWorldService,如下圖:
image
不過按下[確定]後馬上得到一個錯誤訊息,但該錯誤也不是回應出真正的錯誤內容,不過無法作業也是可以想見的!之後說明。
image
而且所產生出來的Reference.c參考檔案也是空空如也,什麼都沒有!如下畫面:
image
為什麼後來筆者有想到原因了呢?因為當您手動敲入Remoting的Proxy也就是遠端物件時,因為該物件必須繼承
System.Web.Services.Protocols.SoapHttpClientProtocol,


這本來在參考的畫面就應該要看出來了,但是因為當初Silverlight為了使下載下來的Plug-In安裝檔盡量愈小愈好,所以是沒有包入System.Web.Service.dll這一顆DLL的,所以您根本無法在Silverlight中參考使用NET Remoting 或是非base on ASP.NET/ASMX所開發的 Web Service



image 


所以此問題是無解的!!!.. =”=


有看到這裡的朋友還是要謝謝您的耐心... 哈哈 (開玩笑),不過筆者有時候經由實做會想起很多事情,不知道是不是年紀大了忘記很多事情...


不過起碼了解了前因後果。^_^


 


下面是筆者測試用的Remoting的Web.Config與程式碼 (使用掛載IIS方式,因為Silverlight通常無法跨網域存取,因此放在同一個Site中)


註:HelloWorld遠端物件的部分獨立編譯一個DLL檔案


1.遠端物件



   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Web;
   5:  using System.Runtime.Remoting;
   6:  using System.Runtime.Remoting.Channels;
   7:   
   8:  /// <summary>
   9:  /// HelloWorld 的摘要描述
  10:  /// </summary>
  11:  public class HelloWorld: MarshalByRefObject, IHelloWorld
  12:  {
  13:      public string getHelloWorld()
  14:      {
  15:          return "Hello World!!!";
  16:      }
  17:  }


2.介面檔

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Web;
   5:   
   6:  /// <summary>
   7:  /// IHelloWorld 的摘要描述
   8:  /// </summary>
   9:  public interface IHelloWorld
  10:  {
  11:      string getHelloWorld();
  12:  }


3.web.config 的Remoting設定

   1:  <configuration>
   2:      <system.runtime.remoting>
   3:          <application>
   4:              <service>
   5:                  <wellknown mode="Singleton" type="HelloWorld, HelloWorld" objectUri="HelloWorld.rem"/>
   6:              </service>
   7:              <channels>
   8:                  <channel name="MyChannel" priority="100" ref="http"/>
   9:              </channels>
  10:          </application>
  11:      </system.runtime.remoting>
  12:      <system.web>
  13:          <compilation debug="true" targetFramework="4.0"/>
  14:      </system.web>
  15:  </configuration>


留言

這個網誌中的熱門文章

什麼是 gRPC ?

什麼是 gRPC(二)- 來撰寫第一個 Hello World 吧!

常見的程式碼壞味道(Code Smell or Bad Smell)