1

I am trying to improve the speed of a C# job, let's call it 'WidgetProcessor'. In one run, WidgetProcessor will process about 5,000 widgets and take about 12 hours to complete (about 8 seconds/widget).

WidgetProcessor makes references to 3 different web services and calls them multiple times for each widget processed. There are various performance/design improvements that can be made to the 'WidgetProcessor' program, but I want to test if the multiple web service calls over the network cause the job to run slow.

I have the source code for each of the three web services (and have access to all of the resources those web services use), and I'm wondering if there is a way to easily use the web service interfaces in WidgetProcessor by referencing the web service projects themselves (instead of calling the web service over the network). The web services are implemented in C#.

I would reference the service implementation classes directly, but the main problem I'm running into is that the web services have collectively about 100 data contracts and the public facing names are different than the implementation classes.

[DataContract(Name = "WidgetInfo")]
public class WidgetDataContract
{
      // DataMembers
}

Thus, referencing implementations directly means I'd be making many code changes in WidgetProcessor. Rather, I'd like to use the service interfaces, so that code changes can stay at a minimum.

Basically, I want a service in my WidgetProcessor solution that looks and acts like a web service, but doesn't perform its operations over the network.

Is this even possible?

1 Answer 1

1

You can add adapter classes which subclass the implementation with the name specified in the datacontract:

public class WidgetInfo : WidgetDataContract { }

If you are finding the overhead of the service call to be overly expensive, you may see benefit of going to a different binding or serialization format. WCF can approach in-process speed when tuned properly.


Edit: If you are intent on not modifying any code, you do have a couple options, but I think they are solutions in search of a problem:

  • Mono.Cecil or Roslyn to automatically map between the classes pre- or post-build
  • For only the types, you could use TypeForwardedToAttribute, but property access is problematic. This may be dependent upon placing the svcutil generated classes in another assembly.
  • Use Castle to build dynamic proxies and map access based off of attributes
Sign up to request clarification or add additional context in comments.

2 Comments

This solution works, but requires a lot of wrapper classes. Some data members inside of data contracts are also renamed, so data members would require wrapping too.
@SuperSimple, those are the options. I added a couple more, but what performance are you looking for from the service? >10k calls/second is easily attainable with WCF.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.