Remote Procedure Calls

  • Thread starter Thread starter Jon Harrop
  • Start date Start date
J

Jon Harrop

So I'm just having a play with RPCs from C# using WSDL to generate lots of
C# code, compile it, load it in as a DLL and then call the functions. It
occurs to me that .NET should facilitate the run-time code generation that
makes these things so easy in languages like Python but Microsoft chose the
code-generation and compilation route. Why? Can you not use reflection to
build an API on-the-fly?
 
Jon,

No, you can't use Reflection, because you don't have a type to reflect
off of. That's what WSDL is for, it is the equivalent of a Type (more or
less) in web-services parlance. All that generated code is doing the work
of generating .NET type equivalents for the WSDL definition of the methods
exposed.

Now, if you look at the generated code, you'll notice that the class
derives from the SoapHttpClientProtocol class. There is nothing stopping
you from creating an instance of this class and setting the URL of the
service, then calling the Invoke method, passing the parameters you want to
the service, and getting the results. This is exactly what the typed
methods on the proxy do.

If you need to get further down to the metal, and want to process the
XML message that is returned to you, then you might want to use WCF, as it
will give you direct access to the message sent over the wire, and you can
work with it from there.
 
Jon said:
So I'm just having a play with RPCs from C# using WSDL to generate lots of
C# code, compile it, load it in as a DLL and then call the functions. It
occurs to me that .NET should facilitate the run-time code generation that
makes these things so easy in languages like Python but Microsoft chose the
code-generation and compilation route. Why? Can you not use reflection to
build an API on-the-fly?

They could.

But there are not much point.

C# is intended as a static typed language. If you wanted
dynamic typing you would use another language.

Arne
 
Nicholas said:
No, you can't use Reflection, because you don't have a type to reflect
off of.

Can you not use obj and make the RPC "obj list -> obj"?
Now, if you look at the generated code, you'll notice that the class
derives from the SoapHttpClientProtocol class. There is nothing stopping
you from creating an instance of this class and setting the URL of the
service, then calling the Invoke method, passing the parameters you want
to the service, and getting the results. This is exactly what the typed
methods on the proxy do.

Great. That may well be a better option for me.

Many thanks,
 
Back
Top