Solved

.Net remoting with asp.nent client

Posted on 2006-06-26
7
646 Views
Last Modified: 2008-02-01
Dear Experts, i have a .NET remoting server app which runs on a comm server and i have a remoting client winapp which i can control mp3 playback on multiple soundcards. Now i would like to do the same thing on web based. using back the same codes as in my remoting client winapp. i got errors like -

System.Runtime.Remoting.RemotingException was unhandled by user code
  Message="Attempt to redirect activation of type 'IAudio, App_Code.amdtefbr' which is already redirected."
  Source="mscorlib"

How do i go about to call methods remotely from asp.net client? thanks for reading.

 
0
Comment
Question by:jaxrpc
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:Nandakumar Sakthivel
ID: 16982371
Hi,
    In the Application_Start event of global.asax file specify the remote configuration file that you are using for configuring remoting(It will hold the remoting server name and type of channels and formatting used)

          RemotingConfiguration.Configure(HttpContext.Current.Server.MapPath(<file name with path>))  (Include this in application_onstart)

Consider the name of the file as remoting.exe.config
The file should have the following syntax

<configuration>
  <system.runtime.remoting>
    <application>            
         <client url="http://<server name>/<remoting virtual directory>">
              <activated type=<class name>,<assembly name>" />  
            </client>
         <channels>
                   <channel ref="http" useDefaultCredentials="true">            
            <clientProviders>                  
            <formatter ref="binary" />
            </clientProviders>
           <serverProviders>                  
               <formatter ref="binary" typeFilterLevel="Full" />
           </serverProviders>                  
           </channel>
   </channels>
    </application>
  </system.runtime.remoting>
  <system.web>
      <customErrors mode="On" />
</system.web>
</configuration>

In the above config example it had used binary formatting with http channel(You can change this as per your requirement).
where class name is the name of the class that you are activating in the assembly.

In the remoting server machine create a virtual directory and put your dlls in the physical folder and place a web.config file to say the type of formatting and channels that you are using

example of that is

<system.runtime.remoting>
            <application>
                  <channels>
                        <channel ref="http">
                              <serverProviders>                  
                                    <formatter ref="binary" typeFilterLevel="Full" />
                                          </serverProviders>
                        </channel>
                  </channels>
                       <service>
                            <activated type=<class name>,<assembly name>" />  
                       </service>
            </application>
</system.runtime.remoting>
 
There are two types of activation of remoting object(client and server). you can use as per your requirements

Thanks,
Nanda
0
 

Author Comment

by:jaxrpc
ID: 16982440
thanks for the info i will try them. just a question. can i use the tcp protocol for asp.net?
0
 

Author Comment

by:jaxrpc
ID: 16982457
sorry left out 1 thing.

You said :
In the remoting server machine create a virtual directory and put your dlls in the physical folder and place a web.config file to say the type of formatting and channels that you are using

If my remoting server app is a windows app, are the above steps still necessary? what's the rational for doing it?

thks
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 6

Expert Comment

by:Nandakumar Sakthivel
ID: 16983139
Hi,
    I had explained the remoting configuration only for a web application.Can you explain me your senarion little bit more .You said that your  remoting server app is a windows app(Is it an exe file or class library).Whether Your client is also a windows client or browser?.I haven't worked with remoting in windows app

Thanks,
Nanda
   
   
0
 

Author Comment

by:jaxrpc
ID: 16989143
hi, my remoting server is an exe and the client to talk to it will be an asp.net client.
0
 
LVL 6

Expert Comment

by:Nandakumar Sakthivel
ID: 16990282
Hi,

    http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21898800.html

The above link has an example of using remoting as windows app.

Thanks,
Nanda



0
 
LVL 6

Accepted Solution

by:
Nandakumar Sakthivel earned 500 total points
ID: 17000300
Hi,
   I had worked out an example for hosting a windows app as an remoting sever
   Consider that  u had an interface name [Imath] in MathOperations class
   The declaration of the interface is

Public Interface IMath
    Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
    Function Subtract(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
End Interface

Had methods for Adding and subtracting two numbers

Consider that, [RemotingServer] is the class that you are hosting as a server(an exe file)
It has the following definition which implements the [IMath] interface
[IMAth] interface is added as an reference to the project(Server app)
 
Public Class Add
    Inherits MarshalByRefObject
    Implements MathOperations.IMath

    Public Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As Integer Implements  MathOperations.IMath.Add
        Return num1 + num2
    End Function

    Public Function Subtract(ByVal num1 As Integer, ByVal num2 As Integer) As Integer Implements    MathOperations.IMath.Subtract
        Return num1 - num2
    End Function
End Class
/*The above class will add or subtract two numbers which will be running as an remote application*/

 You need to use the following to activate the remoting server (So that the remote server will wait for any requests) in the server

         Dim channel As New TcpChannel(8989) /Server is using a tcp channel and it will be waiting in the port 8989 for any requests */
         ChannelServices.RegisterChannel(channel)/*Register the channel so that the port will be used for this particular application only*/
         Dim object1 As New Add    /*Add is the class used in the remoting server which has the two methods */
         Dim ref1 As ObjRef = RemotingServices.Marshal(object1, "object1uri")   /* Creates the single instance of ServiceClass. All clients will use this instance. It will create a proxy and send this proxy object to the client */

When you had finished configuring the server .you need to make the server run manually or can use windows services so that the server application will wait for requests

In the client side if it is a web client.Give a reference to the IMath interface in the client project
In the application_onstart include the following code

    Dim channel As New TcpChannel(0) /*Client app will use port number 0 to communicate with server*/
    ChannelServices.RegisterChannel(channel)
    RemotingConfiguration.RegisterWellKnownClientType(GetType(MathOperations.IMath), "tcp://localhost:8989/object1uri") /*object1uri is the one that we specified in the server side which identifies the hosted remoting app*/

In any button click function in the client side you can include the following

            Dim Client As MathOperations.IMath
            Client = CType(Activator.GetObject(GetType(MathOperations.IMath), "tcp://localhost:8989/object1uri"), MathOperations.IMath)
            Dim i As Integer
            i = Client.Add(1, 5)

The above function will Execute the Add method in the server side and will return back you the value.
You must start the server app manually or you can use windows servies in the server side so that it will wait for any request

Hope this will help you

Thanks,
Nanda
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now