2

I'm interested in creating a web service endpoint in C#/.NET that is fully configurable. To keep it simple assume there is no GET/query/retrieval requirement. I just need some guidance on how to get started here.

The goal is to have a a core solution built, tested, and deployed that can then be configured for new objects thus avoiding a requirement to modify, build, and deploy the entire solution anytime an object is added/removed/modified. This configuration would have to support versioning given the environment it will operate in.

Assume we have a configuration file such as the following:

{
  "V1": {
    "Person": [
      {
        "Name": "FirstName",
        "Required": true,
        "Type": "string",
        "MaxLength": 25
      },
      {
        "Name": "Lastname",
        "Required": true,
        "Type": "string",
        "MaxLength": 25
      },
      {
        "Name": "Title",
        "Required": false,
        "Type": "string",
        "MaxLength": 50
      }
    ]
  },
  "V2": {
    "Person": [
      {
        "Name": "FirstName",
        "Required": true,
        "Type": "string",
        "MaxLength": 25
      },
      {
        "Name": "Lastname",
        "Required": true,
        "Type": "string",
        "MaxLength": 25
      },
      {
        "Name": "Title",
        "Required": false,
        "Type": "string",
        "MaxLength": 50
      },
      {
        "Name": "DateOfBirth",
        "Required": false,
        "Type": "DateTime"
      }
    ]
  }
}

With this configuration I want an application that will expose an endpoint for a caller to send an object and validate the object against the type rules. It should also expose a WSDL.

To be clear, I do not want to write a simple single generic endpoint that can take an array of key-value attributes and then validate - I want to generate a contract.

In essence, I'm trying to have a contract web service while not having to create POCOs. This will allow senders to more easily mock the endpoint for their development work.

For the curious, the incoming data will be sent to a messaging bus to be processed by other services. Thus, the endpoint needs to do the evaluation of type/length/etc but I don't want to create/update the POCOs and controllers along with all the testing and headaches of an enterprise deployment simply because some object has a new field.

1

The traditional way to do this is to define the types in a XSD file and define the service contract in a WSDL file that references the XSD files. You're doing pretty much the same thing in a bespoke JSON format, which is fine if you want to do the work, but you won't find there are a lot of tools out there to help you.

One problem you will quickly discover is that, while it is fairly trivial to define an interface from configuration or markup, that doesn't get you very far, because you will still need code to handle service calls. Since you say you don't want to work with tag/value pairs, that means your code will need to be strongly typed, meaning that a generalized solution is not possible.

I suppose you could build something that will dynamically generate code to translate from the strongly-typed service message to a general format c# data structure. Which sounds an awful lot like the tag/value sort of solution you were avoiding. So you're not really solving a problem, just moving it, albeit you will move it from the public interface to private code.

0

Not sure if I've completely understood but I've successfully implemented a general service for any contract using WCF 4 routing in order to execute, record & playback SOAP messages. Your use may or may not be in the same vein but try these links (I know links are not supposed to be posted as an answer but the articles are too big to summarise)

Microsoft current documentation

Michele Bustamante wrote some articles too. Not sure if these are what I used - I can't seem to find the originals but these seem to cover it:

Part 1

Part 2

Another example

The key to it is this

namespace WcfRouterService
{
    [ServiceContract]
    public interface IRouter
    {
        [OperationContract(Action = "*", ReplyAction = "*")]
        Message Action(Message msg);
    }



public Message Action(Message msg)
        {
            try
            {                    
                return ProcessMessage(msg);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.ToString());
                throw;
            }
        }
}

Not sure if that helps or not and I didn't use JSON.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.