4.1 Two-Way Method Invocation Using TCP-Binary

This code sample illustrates the message exchanged for a Remote Method invocation.

In this sample the client invokes the SendAddress method defined in the Server Interface RemotingTest.MyServer defined as follows.

 namespace RemotingTest
 {
   interface MyServer
   {
     System.String SendAddress(Address address);
   }
  
   class Address
   {
     System.String Street;
     System.String City;
     System.String State;
     System.String Zip;
   }
 }
  

The client invokes the method with the following values for the parameters:

Address.Street = "One Microsoft Way",

Address.City = "Redmond",

Address.State = "WA"

Address.Zip = "98054".

The server is configured to support TCP and the messages are expected to be encoded in [MS-NRBF]. The remoting server is a Single-Call SAO at "tcp://RemotingMachine:8080/MyServer.Rem".

The Remote Method returns a value of "Address received" in the response message to the client.

A sequence diagram for the preceding message exchange pattern is provided in the following figure.

A sequence diagram for the preceding message exchange pattern

Figure 8: A sequence diagram for the preceding message exchange pattern

A dump of the request message is as follows.

  
 0000      2E 4E 45 54 01 00 00 00 00 00 74 01 00 00 04 00 .NET......t.....
 0010       01 01 22 00 00 00 74 63 70 3A 2F 2F 6D 61 68 65       .."...tcp://mahe
 0020      73 68 64 65 76 32 3A 38 30 38 30 2F 4D 79 53 65 shdev2:8080/MySe
 0030       72 76 65 72 2E 72 65 6D 06 00 01 01 18 00 00 00       rver.rem........
 0040      61 70 70 6C 69 63 61 74 69 6F 6E 2F 6F 63 74 65 application/octe
 0050       74 2D 73 74 72 65 61 6D 00 00                      t-stream..
  

The interpretation of the preceding message frame is as follows.

 ProtocolIdentifier: 0x54454E2E
 MajorVersion: 1 (0x1)
 MinorVersion: 0 (0x0)
 OperationType: Request (0x00)
 ContentLength
 ContentDistribution : ContentLength (0x00)
 ContentLength: 314 (0x13A)
 Header 1:
       RequestUriHeader
             HeaderToken: RequestUri (0x04)
             DataType:  CountedString (0x01)
             StringEncoding: UTF8 (0x01)
             UriValue : tcp://RemotingTestMachine:8080/MyServer.rem
 Header 2:
       ContentTypeHeader: 
             HeaderToken: ContentType (0x06)
                 DataType: CountedString (0x01)
                 ContentTypeValue: application/octet-stream
 Header 3:
       EndHeader: 
             HeaderToken: EndOfHeaders(0x00)
  
  
  • The OperationType field indicates this is a Request message of a Two-Way Method.

  • The ContentDistribution field indicates that the message content is not chunked.

  • The ContentLength field indicates the length of the message content in bytes.

  • The RequestUriHeader header contains the Request URI of the server.

  • The ContentTypeHeader header indicates the format identifier to be binary serialization format.

  • The EndHeader header indicates the end of the headers and the message frame.

      
     0000             00 01 00 00 00 FF FF FF FF 01 00 00 00 00 00 00 .....ÿÿÿÿ.......
     0010       00 15 14 00 00 00 12 0B 53 65 6E 64 41 64 64 72 ........SendAddr
     0020       65 73 73 12 6F 44 4F 4A 52 65 6D 6F 74 69 6E 67 ess.oDOJRemoting
     0030      4D 65 74 61 64 61 74 61 2E 4D 79 53 65 72 76 65 Metadata.MyServe
     0040      72 2C 20 44 4F 4A 52 65 6D 6F 74 69 6E 67 4D 65 r, DOJRemotingMe
     0050      74 61 64 61 74 61 2C 20 56 65 72 73 69 6F 6E 3D tadata, Version=
     0060      31 2E 30 2E 32 36 32 32 2E 33 31 33 32 36 2C 20 1.0.2622.31326, 
     0070      43 75 6C 74 75 72 65 3D 6E 65 75 74 72 61 6C 2C Culture=neutral,
     0080      20 50 75 62 6C 69 63 4B 65 79 54 6F 6B 65 6E 3D  PublicKeyToken=
     0090      6E 75 6C 6C 10 01 00 00 00 01 00 00 00 09 02 00 null............
     00A0      00 00 0C 03 00 00 00 51 44 4F 4A 52 65 6D 6F 74 .......QDOJRemot
     00B0      69 6E 67 4D 65 74 61 64 61 74 61 2C 20 56 65 72 ingMetadata, Ver
     00C0      73 69 6F 6E 3D 31 2E 30 2E 32 36 32 32 2E 33 31 sion=1.0.2622.31
     00D0      33 32 36 2C 20 43 75 6C 74 75 72 65 3D 6E 65 75 326, Culture=neu
     00E0      74 72 61 6C 2C 20 50 75 62 6C 69 63 4B 65 79 54 tral, PublicKeyT
     00F0      6F 6B 65 6E 3D 6E 75 6C 6C 05 02 00 00 00 1B 44 oken=null......D
     0100      4F 4A 52 65 6D 6F 74 69 6E 67 4D 65 74 61 64 61 OJRemotingMetada
     0110      74 61 2E 41 64 64 72 65 73 73 04 00 00 00 06 53 ta.Address.....S
     0120      74 72 65 65 74 04 43 69 74 79 05 53 74 61 74 65 treet.City.State
     0130      03 5A 69 70 01 01 01 01 03 00 00 00 06 04 00 00 .Zip............
     0140      00 11 4F 6E 65 20 4D 69 63 72 6F 73 6F 66 74 20 ..One Microsoft 
     0150      57 61 79 06 05 00 00 00 07 52 65 64 6D 6F 6E 64 Way......Redmond
     0160      06 06 00 00 00 02 57 41 06 07 00 00 00 05 39 38 ......WA......98
     0170      30 35 34 0B                                       054.
      
      
    

The interpretation of the preceding message content is as follows.

 Binary Serialization Format
 SerializationHeaderRecord:
       BinaryHeaderEnum: SerializedStreamHeader (0x00)
       TopId: 0 (0x0)
       HeaderId: -1 (0xFFFFFFFF)
       MajorVersion: 1 (0x1)
       MinorVersion: 0 (0x0)
 BinaryMethodCall: 
       BinaryHeaderEnum: BinaryMethodCall (0x15)
       MessageEnum: 00000014
             NoArgs:                 (...............................0) 
             ArgsInline:             (..............................0.) 
             ArgsIsArray:            (.............................1..) 
             ArgsInArray:            (............................0...) 
             NoContext:              (...........................1....) 
             ContextInline:          (..........................0.....) 
             ContextInArray:         (.........................0......) 
             MethodSignatureInArray: (........................0.......) 
             PropertyInArray:        (.......................0........) 
             NoReturnValue:          (......................0.........) 
             ReturnValueVoid:        (.....................0..........) 
             ReturnValueInline:      (....................0...........) 
             ReturnValueInArray:     (...................0............) 
             ExceptionInArray:       (..................0.............) 
             Reserved:               (000000000000000000..............)
       MethodName: 
             PrimitiveTypeEnum: String (0x12)
             Data: SendAddress
       TypeName: 
             PrimitiveTypeEnum: String (0x12)
  
             Data: RemotingTest.MyServer, RemotingTest, Version=1.0.2616.21414, 
 Culture=neutral, PublicKeyToken=null
   MethodCallArray:(ArraySingleObject)
             BinaryHeaderEnum: ArraySingleObject (0x10)
             ObjectId: 1 (0x01)
             Length: 1 (0x1)
   MemberReference:
             BinaryHeaderEnum: MemberReference (0x09)
             IdRef: 2 (0x02)
   BinaryLibrary:
             BinaryHeaderEnum: BinaryLibrary (0x0C)
             AssemId: 3 (0x03)
             LibraryString: LibraryString:RemotingTest, 
 Version=1.0.2621.26113, Culture=neutral, PublicKeyToken=null
   ClassWithMembersAndTypes:
             BinaryHeaderEnum: ClassWithMembersAndTypes (0x05)
             ObjectId: 2 (0x02)
             Name: RemotingTest.MyData
             NumMembers: 4 (0x04)
                   MemberNames:
                         Data: Street
                   MemberNames:
                         Data: City
                   MemberNames:
                         Data: State
                   MemberNames:
                         Data: Zip
             BinaryTypeEnumA:
                   String  (0x01)
                   String  (0x01)
                   String  (0x01)
                   String  (0x01)
             AssemId: 3 (0x03)
   BinaryObjectString:
             BinaryHeaderEnum: BinaryObjectString (0x06)   
             ObjectId: 04 (0x04)
             Length: 17 (0x11)
             Value: One Microsoft Way
   BinaryObjectString:
             BinaryHeaderEnum: BinaryObjectString (0x06)   
             ObjectId: 05 (0x04)
             Length: 7 (0x07)
             Value: Redmond
   BinaryObjectString:
             BinaryHeaderEnum: BinaryObjectString (0x06)   
             ObjectId: 06 (0x04)
             Length: 2 (0x02)
             Value: WA
   BinaryObjectString:
             BinaryHeaderEnum: BinaryObjectString (0x06)   
             ObjectId: 07 (0x04)
             Length: 5 (0x05)
             Value: 98054
   MessageEnd:
             BinaryHeaderEnum: MessageEnd (0x11)
  
  • The BinaryMethodCall record contains the Server Type name and the Remote Method name. The ArgsIsArray flag in the MessageEnum field indicates that the Arguments are passed as part of a MethodCallArray record. The NoContext flag in the MessageEnum field indicates that there is no CallContext that is sent as part of this message.

  • The MethodCallArray record contains one entry for the only Argument.

  • The MemberReference record provides a reference to the actual value.

  • The BinaryLibrary record associates the Id value of 3 to the Library name RemotingTest, Version=1.0.2621.26113, Culture=neutral, PublicKeyToken=null.

  • ClassWithMembersAndTypes record contains the Input Argument passed. It lists the four Member names and their Remoting Types (all strings in this case).

  • Four BinaryObjectString records contain the string values of the four Members (Street, City, State and Zip).

The message frame and the message content for the response message from the server are as follows.

  
 0000             2E 4E 45 54 01 00 02 00 00 00 27 00 00 00 00 00 .NET......'.....
  
  

The interpretation of the preceding message frame is as follows.

 ProtocolIdentifier: 54454E2E 
 MajorVersion: 1 (0x1)
 MinorVersion: 0 (0x0)
 OperationType: Response (0x02)
 ContentLength
       ContentDistribution : ContentLength (0x00)
       ContentLength: 39 (0x27)
 Header 1:
       EndHeader: 
             HeaderToken: EndOfHeaders(0x00)
  
  • The OperationType field indicates that this is a Response message of a Two-Way Method.

  • The ContentDistribution field indicates that the message content is not chunked.

  • The ContentLength field indicates the length of the message content in bytes.

  • The EndHeader header indicates the end of the headers and the message frame.

      
     0000             00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 ................
     0010      00 16 11 08 00 00 12 10 41 64 64 72 65 73 73 20 ........Address 
     0020      72 65 63 65 69 76 65 64 0B                      received.
      
      
    

The interpretation of the preceding message content is as follows.

 Binary Serialization Format
   SerializationHeaderRecord:
         BinaryHeaderEnum: SerializedStreamHeader (0x00)
       TopId: 0 (0x0)
       HeaderId: 0 (0x0)
       MajorVersion: 1 (0x1)
       MinorVersion: 0 (0x0)
   BinaryMethodReturn: 
       BinaryHeaderEnum: BinaryMethodReturn (0x16)
       MessageEnum: 00000811
             NoArgs:                 (...............................1) 
             ArgsInline:             (..............................0.) 
             ArgsIsArray:            (.............................0..) 
             ArgsInArray:            (............................0...) 
             NoContext:              (...........................1....) 
             ContextInline:          (..........................0.....) 
             ContextInArray:         (.........................0......) 
             MethodSignatureInArray: (........................0.......) 
             PropertyInArray:        (.......................0........) 
             NoReturnValue:          (......................0.........) 
             ReturnValueVoid:        (.....................0..........) 
             ReturnValueInline:      (....................1...........) 
             ReturnValueInArray:     (...................0............) 
             ExceptionInArray:       (..................0.............) 
             Reserved:               (000000000000000000..............)
       ReturnValue: 
             PrimitiveTypeEnum: String (0x12)
             Data: Address received
       ArgsCount: 0 (0x0)
   MessageEnd:
             BinaryHeaderEnum: MessageEnd (0x0B)
  

The BinaryMethodReturn record indicates that the message content is a response to a message. The NoArgs and the NoContext flags in the MessageEnum field indicate that there is no Output Arguments or Call Context associated with this call. The ReturnValueInline flag in the MessageEnum field indicates that the Return Value is part of the Method Return record. The actual value is encoded as StringValueWithCode.