WCF Service-Oriented Application series 16th: message exchange mode (MEP)-Request/response operations

Source: Internet
Author: User

The message exchange patterns in WCF is divided into request/reply, one-way, duplex, or callback );

This chapter mainly introduces request/reply operations. Request/response operations are the default actions of all service operations. By viewing the WSDL description, we can see <WSDL: description of input> and <WSDL: output> messages. The message can contain request parameters, returned data, <body> elements, or returned soap errors.

In a request/response operation, the client sends a request in the form of a message, which blocks the client until it receives the Response Message. The default response timeout value is 1 minute. If the service still does not respond after this time, the client will get a timeoutexception exception. The request/response is similar to the classic Client/Server programming model. The returned response message includes the returned result, or it converts the returned value to the return value of a common method. In addition, if there is a communication exception or a server exception, the proxy throws an exception on the client. Except for binding netpeertcpbinding and netmsmqbinding, all bindings support request/response operations.

The request/response operation mode is as follows:

Next we will introduce the request/response operations through a demo:

MainCodeAs follows:

Interface code:

  [Servicecontract (namespace  =     "  Http://schemas.xinhaijulan.com/demos/RequestReply  "  )]
Public Interface Ihellowcf
{
[Operationcontract (name = " Getmessagecontract " , Action = " URN: acioninput " , Replyaction = " URN: actionoutput " )]
String Getmessage ( String MSG );
}

Implementation Code:

 

    Public     Class  Hellowcf: ihellowcf
{
Public String Getmessage ( String MSG)
{
Return " Message from client is: " + MSG;
}
}

Server code:

    Static    Void  Main (  String  [] ARGs)
{
Using (Servicehost host = New Servicehost ( Typeof (Servicelibrary. hellowcf )))
{
Host. addserviceendpoint ( Typeof (Servicelibrary. ihellowcf ), New Nettcpbinding (), " Net. TCP: // localhost: 9000/hellowcf " );
Host. open ();
Console. writeline ( " Please input exit to close host. " );
String Key = Console. Readline ();
While (Key. tolower () ! = " Exit " )
{
Console. writeline ( " Please input exit to close host. " );
Key = Console. Readline ();
}
}
}

Client code:

    Static     Void  Main (  String  [] ARGs)
{
Channelfactory < Servicelibrary. ihellowcf > Channelfactory = New Channelfactory < Servicelibrary. ihellowcf > ( New Nettcpbinding ());
Servicelibrary. ihellowcf Client = Channelfactory. createchannel ( New Endpointaddress ( " Net. TCP: // localhost: 9000/hellowcf " ));


Using (Client As Idisposable)
{
Console. writeline ( " ------------ Begin ------------- " );

Console. writeline (client. getmessage ( " Hello WCF! " ));

Console. writeline ( " ------------ End --------------- " );
}

Console. Readline ();
}

 

Run the code and output it as follows:

 
  ------------Begin-------------
Message from clientIs: Hello WCF!
------------End---------------

Now, the message exchange mode (MEP)-Request/response operation has been introduced.

Click to download the demo.

 
  Author: Xinhai julan
Source: http://xinhaijulan.cnblogs.com
The copyright is shared by the author and the blog. You are welcome to reprint the copyright. However, you must keep this statement without the author's consent andArticleThe original text connection is clearly displayed on the page. Otherwise, the legal liability is retained.

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.