Remoting for Asp.net Protocol

Source: Internet
Author: User

1. Definition Interface

1.1 iduplexcalculator operation interface

 
PublicInterfaceIcalculatorcallback
{
VoidShowresult (DoubleX,DoubleY,DoubleResult );
}

1.2 define the callback interface icalculatorcallback

 
 PublicInterfaceIcalculatorcallback
{
VoidShowresult (DoubleX,DoubleY,DoubleResult );
}

2. Define server-side operations such as duplexcalculatorremoting, which must inherit albyrefobject,

 
Iduplexcalculator
Public ClassDuplexcalculatorremoting: marshalbyrefobject, iduplexcalculator

{

Public VoidAdd (DoubleX,DoubleY, icalculatorcallback callback)

{

//Console. writeline ("invoke the method add ({0}, {1}).", x, y );

DoubleResult = x + y;

Callback. showresult (X, Y, result );

}

}

3. Define the host

3.1 class Program
{
Static void main (string [] ARGs)
{
System. runtime. remoting. remotingconfiguration. Configure ("hosting.exe. config", false );
Console. writeline ("Calculator Service has begun to Listen ......");
Console. Read ();
}
}

Modify the remoting service.

3.2 Definition configuration file

View code

<Configuration>
<System. runtime. remoting>
<Application name =" Calculator " >
<Service>
<Wellknown mode = " Singlecall "
Type = " Duplexcalculatorremoting. duplexcalculatorremoting, duplexcalculatorremoting "
Objecturi = " Duplexcalculator. Soap " />
</Service>

<Channels>
<Channel Ref = " HTTP " Port = " 8080 " >
<Serverproviders>
<Provider Ref = " WSDL " />
<Formatter Ref = " Binary " Typefilterlevel = " Full " />
</Serverproviders>
<Clientproviders>
<Formatter Ref = " Binary " />
</Clientproviders>
</Channel>
</Channels>
</Application>
</System. runtime. remoting>
</Configuration>

<Application name = "Calculator"> objecturi = "duplexcalculator. Soap"/>

Http: // localhost: 8080/calculator/duplexcalculator. url used by the producer on the soap Client

Here you need to reference the interface type and operation type.

4. Guest terminal license

View code

   Public   Partial   Class _ Default: system. Web. UI. Page
{

Calculatorcallbackhandler calcul = New Calculatorcallbackhandler ();
Protected Void Page_load ( Object Sender, eventargs E)
{
System. runtime. remoting. remotingconfiguration. Configure (server. mappath ( " Web. config " ), False );
Calcul. myevent + = New Eventhandler (calcul_myevent );
Invocateduplexcalculator ( " Http: // localhost: 8080/calculator/duplexcalculator. Soap " );
// Invocateduplexcalculator (" Http: // localhost/duplexcalculatorremoting/duplexcalculator. Soap ");

}

Void Calcul_myevent ( Object Sender, eventargs E)
{
Textbox1.text = (calculatorcallbackhandler) sender). value;
}

Private Void Invocateduplexcalculator ( String Remoteaddress)
{
Iduplexcalculator proxy = (iduplexcalculator) activator. GetObject ( Typeof (Iduplexcalculator), remoteaddress );
Proxy. Add ( 1.0 , 2.0 , Calcul );

}
}

The client needs to implement the interface of the response data. As follows:

View code

     Public   Class Calculatorcallbackhandler: marshalbyrefobject, icalculatorcallback
{

Public Event Eventhandler myevent;
# Region Icalculatorcallback members

Public Void Showresult ( Double X,Double Y, Double Result)
{
Value = String . Format ( " X + y = {2} where x = {0} and Y = {1} " , X, Y, result );
If (Myevent! = Null ){
Myevent ( This , Null );
}
}

# Endregion

Public String Value { Get ; Set ;}
}

In the same way, the client needs to configure

As follows:

View code

<System. runtime. remoting>
<Application>
<Channels>
<Channel Ref = " HTTP " Port = " 0 " >
<Clientproviders>
<Formatter Ref = " Binary " />
</Clientproviders>
<Serverproviders>
<Formatter Ref = " Binary " Typefilterlevel = " Full " />
</Serverproviders>
</Channel>
</Channels>
</Application>
</System. runtime. remoting>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.