2012-02-29 90 views
2

我目前在IIS下運行Framework 2上的.Net Remoting應用程序。我必須將其升級到Framework 4才能使用一些新組件。我已經能夠在Framework 2上對所有東西都進行平滑的運行,但是一旦我更改爲Framework 4,當我嘗試調用遠程對象的某個函數時,會出現以下異常。將.Net Remoting從Framework 2遷移到4的問題

The input stream is not a valid binary format. 
The starting contents (in bytes) are: 
53-79-73-74-65-6D-2E-52-75-6E-74-69-6D-65-2E-52-65 ... 

此錯誤是不是真正的錯誤,它是由以下事實遠程對象被拋出異常,和IIS包裹在XML除外,其拋出的BinaryFormatter關閉引起。 See this for more info on the bug

這是因爲我看不出是什麼原因造成的例外,從來沒有使用過任何Remoting是很不幸的,我沒有太多的想法,從哪裏開始調試。在執行代碼之前,似乎拋出了異常,因爲我做了大量的日誌記錄,而且沒有任何一次觸發。

基本上,我正在尋找從人們一些線索或指針遇到類似的問題:

  • 什麼引起的異常時,沒有代碼除了 編譯從.net 2到.NET 4變?
  • 如何獲取返回的完整異常消息?

這裏是獲取遠程對象

Dim clientProvider As BinaryClientFormatterSinkProvider = New BinaryClientFormatterSinkProvider() 
Dim serverProvider As BinaryServerFormatterSinkProvider = New BinaryServerFormatterSinkProvider() 
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full 

tsChannelName = System.Guid.NewGuid().ToString() 

Dim props As IDictionary = New Hashtable() 
props("port") = 0 
props("name") = tsChannelName 
props("typeFilterLevel") = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full 
props("secure") = True 
props("useDefaultCredentials") = True 

Dim Channel As HttpChannel = New HttpChannel(props, clientProvider, serverProvider) 

ChannelServices.RegisterChannel(Channel, False) 

//Get the object on the Server 
Dim rtnComm As I_CMQCComm = Activator.GetObject(GetType(I_CMQCComm), server) 

//Knock knock 
rtnComm.IsAlive() 'Exception is thrown here 

我可以提供更多的信息,如所需要的代碼。

+0

您是否也編譯過.NET 4的客戶端代碼? – 2012-02-29 20:48:20

+0

是的!還改變IIS在ASP.NET 4上運行。我設法通過將我的格式化器更改爲肥皂來查看確切的錯誤。我剛剛設法解決了這個問題,我會發表一個答案:) – Alexandre 2012-02-29 21:11:56

回答

0

好的!

首先看到的錯誤,建議更改使用的格式,這樣,這將是可以看到整個錯誤。

基本上,我有一個服務器不可用和IIS將發送回其甩出格式化HTML。

如何看到錯誤:

Dim clientProvider As SoapClientFormatterSinkProvider = New SoapClientFormatterSinkProvider() 
Dim serverProvider As SoapServerFormatterSinkProvider = New SoapServerFormatterSinkProvider() 

不要忘記更改Web.Config文件也

<channels> 
     <channel ref="http" > 
     <serverProviders> 
      <formatter ref="soap" /> 
      </serverProviders> 
      <clientProviders> 
      <formatter ref="soap" /> 
      </clientProviders> 
     </channel> 
</channels> 

服務器不可用是由於IIS錯誤。錯誤記錄在事件查看器中的應用程序下(控制面板 - >管理工具 - >事件查看器)。

我的錯誤是由於這樣的事實,我改變了Machine.config文件到IIS不會在用戶ASP_NET下運行。然而我不知道的是每個框架都有一個文件。 IIS因爲禁用了用戶ASP_NET,所以沒有用戶啓動aspnet_wp.exe進程。

微小的失誤,希望這能幫助一些人調試他們的.NET遠程。 它在.Net 4下完美運行!