Use .NET Remoting to transfer a file?

孤街醉人 提交于 2020-01-16 04:59:10

问题


I'm using .NET remoting to communicate between a web site and a Windows service. They both live on different machines. I have a statically defined port number for use by all requests and responses.

I also use this mechanism to transfer files from the web site to the Windows service box. I'm passing a Stream object in the object that is being remoted to the Windows service box. The web box is opening another, seemingly random, port to facilitate this request that includes the file Stream.

Is there a way to specify which port this file Stream should use? Anyone know why it doesn't want to use the port I have defined and that all my other requests/responses use with no problem?

I'm using .NET Framework v2.


回答1:


Just read your stream into a byte[] then pass that. Exactly what I did when came across this situation.




回答2:


Here is someone who has implemented file transfer with .NET remoting:

http://www.codeproject.com/KB/dotnet/Net_Remoting_Events.aspx

Source code is available from a link on the page.

However, I agree with the comment from John Saunders that you should move to WCF.




回答3:


Add a method to your remoting object to return a Stream.

Just remember to dispose of it correctly by enclosing it in a using clause.




回答4:


Use "remoting callbacks" passing a "stream like" remote object as parameter.

http://www.codeproject.com/Articles/1584/Using-the-Remoting-Callbacks-in-Net-Applications



来源:https://stackoverflow.com/questions/1104827/use-net-remoting-to-transfer-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!