Click here to Skip to main content
15,897,187 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to pass not simple types using .NET Remoting Pin
Dustin Metzgar1-Aug-06 7:00
Dustin Metzgar1-Aug-06 7:00 
GeneralRe: How to pass not simple types using .NET Remoting Pin
Nigor1-Aug-06 8:22
Nigor1-Aug-06 8:22 
GeneralRe: How to pass not simple types using .NET Remoting Pin
Dustin Metzgar1-Aug-06 8:46
Dustin Metzgar1-Aug-06 8:46 
GeneralRe: How to pass not simple types using .NET Remoting Pin
Nigor1-Aug-06 11:03
Nigor1-Aug-06 11:03 
AnswerRe: How to pass not simple types using .NET Remoting [modified] Pin
Nigor3-Aug-06 9:23
Nigor3-Aug-06 9:23 
AnswerRe: How to pass not simple types using .NET Remoting [modified] Pin
Nigor4-Aug-06 8:03
Nigor4-Aug-06 8:03 
GeneralRe: How to pass not simple types using .NET Remoting Pin
code-frog4-Aug-06 8:21
professionalcode-frog4-Aug-06 8:21 
GeneralRe: How to pass not simple types using .NET Remoting [modified] Pin
Nigor4-Aug-06 9:10
Nigor4-Aug-06 9:10 
Thanks for the quick reply. I actually figured out the problem. May not be a problem after all, just the way .NET developers designed the library. There is a peculiar channel property called "machineName" which by default you shouln't have to worry about: http://msdn2.microsoft.com/en-us/library/kw7c6kwc(d=ide).aspx#machineName

Setting the property on the server to the current "outside" address solves the problem !!! Here is what I think happens:

When ShowText() is called, nothing special takes place b/c the client knows what to pass and what to get back. Done deal. With ShowFileInfo(), the FileInfo object can incurr additional calls from the client side. That is why in that case the server will return a message with a bunch of stuff and one of them being the server's ip address. Dont know whats the need for that, since the client already knows the server's ip address. But the server is "dumb" enough to put its local address in message, not the wan address. So setting "machineName" to the wan address of the server does the trick. Here is the soap message returned by the server to the client upon ShowFileInfo():

http://img185.imageshack.us/img185/1772/remotingtestworksfu1.png

Note how item id="ref-17 is now set to "igor.no-ip.ca:1024" as opposed to "10.0.0.1:1024". It makes sence now.


So here, in all glory is a working code:
----------------------------------------

Client:
<br />
using System;<br />
using System.Collections;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Runtime.Remoting;<br />
using System.Runtime.Remoting.Channels;<br />
using System.Runtime.Remoting.Channels.Http;<br />
using System.IO;<br />
<br />
namespace RemotingTest<br />
{<br />
    class Program<br />
    {<br />
        static void Main(string[] args)<br />
        {<br />
            IDictionary properties = new Hashtable();<br />
<br />
            SoapClientFormatterSinkProvider clientSinkProvider = new SoapClientFormatterSinkProvider();<br />
            SoapServerFormatterSinkProvider serverSinkProvider = new SoapServerFormatterSinkProvider();<br />
<br />
            serverSinkProvider.TypeFilterLevel =<br />
                System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;<br />
<br />
            properties["name"] = "";<br />
            properties["port"] = 0;<br />
            properties["typeFilterLevel"] = "Full";<br />
<br />
            HttpChannel commChannel = new HttpChannel(properties, clientSinkProvider, serverSinkProvider);<br />
            <br />
            ChannelServices.RegisterChannel(commChannel, false);<br />
<br />
            RemotingConfiguration.RegisterWellKnownClientType(<br />
                typeof(ServerInterface),<br />
                "http://igor.no-ip.ca:1024/Server"); // change to appropriate address here<br />
<br />
            ServerInterface server = new ServerInterface();<br />
<br />
            string text = "";<br />
            <br />
            while((text = Console.ReadLine()) != "Quit")<br />
            {<br />
                Console.WriteLine(server.ShowText("testing string"));<br />
                Console.WriteLine(server.ShowFileInfo(text).Name);<br />
            }<br />
<br />
            Console.Read();<br />
        }<br />
    }<br />
}<br />


Server Interface:
-----------------------

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.IO;<br />
<br />
namespace RemotingTest<br />
{<br />
    public class ServerInterface: MarshalByRefObject <br />
    {<br />
        public FileInfo ShowFileInfo(string filename)<br />
        {<br />
            Console.WriteLine("Filename " + filename + " requested");<br />
            <br />
            return new FileInfo(filename);<br />
        }<br />
<br />
        public string ShowText(string text)<br />
        {<br />
            Console.WriteLine(text);<br />
<br />
            return "\"" + text + "\" show on the server.";<br />
        }<br />
    }<br />
}<br />


Server:
-------------------

<br />
using System;<br />
using System.Collections;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Runtime.Remoting;<br />
using System.Runtime.Remoting.Channels;<br />
using System.Runtime.Remoting.Channels.Http;<br />
<br />
namespace RemotingTest<br />
{<br />
    class Program<br />
    {<br />
        static void Main(string[] args)<br />
        {<br />
            IDictionary properties = new Hashtable();<br />
<br />
            SoapServerFormatterSinkProvider serverSinkProvider = new SoapServerFormatterSinkProvider();<br />
<br />
            serverSinkProvider.TypeFilterLevel =<br />
                System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;<br />
<br />
            properties["name"] = "";<br />
            properties["port"] = 1024;<br />
            properties["typeFilterLevel"] = "Full";<br />
            properties["machineName"] = "igor.no-ip.ca"; // THE MAGIC LINE !!!<br />
            <br />
            HttpChannel commChannel = new HttpChannel(properties, null, serverSinkProvider);<br />
            <br />
            ChannelServices.RegisterChannel(commChannel, false);<br />
<br />
            RemotingConfiguration.RegisterWellKnownServiceType(<br />
                typeof(ServerInterface),<br />
                "Server", WellKnownObjectMode.SingleCall);<br />
<br />
            Console.Read();<br />
        }<br />
    }<br />
}<br />



----------------------

Now its time for me to write an article on this. Having a router is quite common, and Im sure other programmers will stumble on the same problem.

Thanks for all you help guys!!



-- modified at 15:31 Friday 4th August, 2006
GeneralRe: How to pass not simple types using .NET Remoting Pin
code-frog4-Aug-06 14:46
professionalcode-frog4-Aug-06 14:46 
GeneralRe: How to pass not simple types using .NET Remoting [modified] Pin
Nigor5-Aug-06 3:18
Nigor5-Aug-06 3:18 
QuestionDataGridView Button w/ Image Pin
swcrissman31-Jul-06 5:13
swcrissman31-Jul-06 5:13 
QuestionInstance from the active form Pin
Ramez Quneibi31-Jul-06 4:31
Ramez Quneibi31-Jul-06 4:31 
AnswerRe: Instance from the active form Pin
Judah Gabriel Himango31-Jul-06 5:12
sponsorJudah Gabriel Himango31-Jul-06 5:12 
GeneralRe: Instance from the active form [modified] Pin
Ramez Quneibi31-Jul-06 21:36
Ramez Quneibi31-Jul-06 21:36 
GeneralRe: Instance from the active form Pin
Judah Gabriel Himango1-Aug-06 4:39
sponsorJudah Gabriel Himango1-Aug-06 4:39 
GeneralRe: Instance from the active form Pin
Ramez Quneibi1-Aug-06 21:26
Ramez Quneibi1-Aug-06 21:26 
GeneralRe: Instance from the active form Pin
Judah Gabriel Himango2-Aug-06 5:20
sponsorJudah Gabriel Himango2-Aug-06 5:20 
GeneralRe: Instance from the active form Pin
Ramez Quneibi4-Aug-06 5:22
Ramez Quneibi4-Aug-06 5:22 
GeneralRe: Instance from the active form Pin
Judah Gabriel Himango4-Aug-06 10:04
sponsorJudah Gabriel Himango4-Aug-06 10:04 
GeneralRe: Instance from the active form Pin
Ramez Quneibi4-Aug-06 22:47
Ramez Quneibi4-Aug-06 22:47 
QuestionCopy an instance Pin
sjembek31-Jul-06 4:30
sjembek31-Jul-06 4:30 
AnswerRe: Copy an instance Pin
Dustin Metzgar31-Jul-06 4:44
Dustin Metzgar31-Jul-06 4:44 
GeneralRe: Copy an instance Pin
sjembek31-Jul-06 5:50
sjembek31-Jul-06 5:50 
GeneralRe: Copy an instance Pin
Dustin Metzgar31-Jul-06 6:25
Dustin Metzgar31-Jul-06 6:25 
GeneralRe: Copy an instance Pin
sjembek31-Jul-06 6:42
sjembek31-Jul-06 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.