Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a WCF service without generating an Assembly

I am trying to write some code in C# that will call a WCF service on the fly by importing the WSDL, examining it and then making calls to it dynamically.

The service I am calling can change from time to time - so if it does I want my client to know about new methods and new input parameters and output parameters to the calls, without rebuilding my client.

One possible solution to this is to import and compile a service reference on the fly.

Outlined here: Creating an assembly on the fly from a WSDL

I would like to avoid the generation of an assembly and then reflecting over it if possible.

I looked into the code of the dynamic proxy in the link and they use a framework class to do the import. This class is the WsdlImporter. So I had thought great - I can use that and examine the WSDL schema and determine what calls are present and what inputs and outputs are available.

The problem is that the type information is missing in the MessagePartDescription objects that the WsdlImporter creates. Apparently this is missing because it cannot find the types yet - see the response to the question from Brian.

So any advice on how I should proceed? Am I completely on the wrong track here?

like image 235
Neil Avatar asked Jan 24 '11 21:01

Neil


People also ask

How do I run a WCF service?

Press Ctrl + F5 to run the service. Open WCF Test Client. To open WCF Test Client, open Developer Command Prompt for Visual Studio and execute WcfTestClient.exe. Select Add Service from the File menu.

Is WCF discontinued?

NET Framework technologies, your WCF applications will continue to work for a long time. In fact, WCF will likely work for the next two decades thanks to . NET Framework being considered part of the windows operating system.


2 Answers

This is probably not an answer but I will post it as one to fully describe my opinion.

Dynamic proxy:
IMO this is example of wrong usage of technology. It is elementary behavior of WSDL - if it changes you have to change client or you have to make good WSDL versioning and create new client.

You still have to somehow say your client to get WSDL - does it mean that you will parse WSDL before each call? Doesn't seem like a good idea.

Information about types is really not part of WSDL because by default WSDL is generated as interoperable. CLR types are not operation needed for interoperability. When you create service proxy by Add service reference or Svcutil it will generate code for types defined in WSDL. That code then need to be compiled.

You can try to use NetDataContractSerializer instead of default DataContractSerializer. NetDataContractSerializer adds CLR type information into WSDL but I still expect that new types must be known to your clients - it means deploying new assembly with types and use it by clients. This almost sounds like same approach when simply deploying assembly with new static client proxy.

Dynamic WF client
I also don't see too much usage of this architecture - you still need to change client to reflect new WF steps, don't you?

Changing the WF
Are we talking about Windows Workflow foundation? I can hardly imagine scenario where you create WF, expose it as a service and then change it. When you expose WF as service you are probably defining long running WF. Long running WFs use persistance which is based on serialization (at least in WF 3.5 but I believe it is same in WF 4). When you change WF definition, all persisted WFs are most probably doomed because they will never ever deserialize. This situation is usually solved by parallel deployment of new and old version where old version is only used to finish incomplete WFs. Again it means new clients.

like image 70
Ladislav Mrnka Avatar answered Nov 11 '22 02:11

Ladislav Mrnka


If you look at the problem from a different angle. Do you need to regenerate the proxy each time or do you need a contract that continues to work when things change?

WCF has a mechanism for this IExtensibleDataContracts see: http://msdn.microsoft.com/en-us/library/ms731083%28v=VS.100%29.aspx

Best practices for versioning of contracts can be found here

like image 1
Shiraz Bhaiji Avatar answered Nov 11 '22 03:11

Shiraz Bhaiji