IService.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Google.ProtocolBuffers.Descriptors;
  5. namespace Google.ProtocolBuffers {
  6. /// <summary>
  7. /// Base interface for protocol-buffer-based RPC services. Services themselves
  8. /// are abstract classes (implemented either by servers or as stubs) but they
  9. /// implement this itnerface. The methods of this interface can be used to call
  10. /// the methods of the service without knowing its exact type at compile time
  11. /// (analagous to the IMessage interface).
  12. /// </summary>
  13. public interface IService {
  14. /// <summary>
  15. /// The ServiceDescriptor describing this service and its methods.
  16. /// </summary>
  17. ServiceDescriptor DescriptorForType { get; }
  18. /// <summary>
  19. /// Call a method of the service specified by MethodDescriptor. This is
  20. /// normally implemented as a simple switch that calls the standard
  21. /// definitions of the service's methods.
  22. /// <para>
  23. /// Preconditions
  24. /// <list>
  25. /// <item><c>method.Service == DescriptorForType</c></item>
  26. /// <item>request is of the exact same class as the object returned by GetRequestPrototype(method)</item>
  27. /// <item>controller is of the correct type for the RPC implementation being used by this service.
  28. /// For stubs, the "correct type" depends on the IRpcChannel which the stub is using. Server-side
  29. /// implementations are expected to accept whatever type of IRpcController the server-side RPC implementation
  30. /// uses.</item>
  31. /// </list>
  32. /// </para>
  33. /// <para>
  34. /// Postconditions
  35. /// <list>
  36. /// <item><paramref name="done" /> will be called when the method is complete.
  37. /// This may before CallMethod returns or it may be at some point in the future.</item>
  38. /// <item>The parameter to <paramref name="done"/> is the response. It will be of the
  39. /// exact same type as would be returned by <see cref="GetResponsePrototype"/>.</item>
  40. /// <item>If the RPC failed, the parameter to <paramref name="done"/> will be null.
  41. /// Further details about the failure can be found by querying <paramref name="controller"/>.</item>
  42. /// </list>
  43. /// </para>
  44. /// </summary>
  45. void CallMethod(MethodDescriptor method, IRpcController controller,
  46. IMessage request, Action<IMessage> done);
  47. /// <summary>
  48. /// CallMethod requires that the request passed in is of a particular implementation
  49. /// of IMessage. This method gets the default instance of this type of a given method.
  50. /// You can then call WeakCreateBuilderForType to create a builder to build an object which
  51. /// you can then pass to CallMethod.
  52. /// </summary>
  53. IMessage GetRequestPrototype(MethodDescriptor method);
  54. /// <summary>
  55. /// Like GetRequestPrototype, but returns a prototype of the response message.
  56. /// This is generally not needed because the IService implementation contructs
  57. /// the response message itself, but it may be useful in some cases to know ahead
  58. /// of time what type of object will be returned.
  59. /// </summary>
  60. IMessage GetResponsePrototype(MethodDescriptor method);
  61. }
  62. }