Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

.Net remoting with asp.nent client

Posted on 2006-06-26
7
652 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 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