Search code examples
c#web-serviceswsdlirs

Refactoring a Method to implement multiple namespaces


I'm attempting to prepare my application code to accept an annual change of a third-party wsdl. I cannot make and have no control over the design of this wsdl. Objects within this wsdl may change, have items added, be removed, etc. However, I still need to keep the previous version(s) of the wsdl.

My plan is to add the current wsdl as a Service Reference, as I did with the previous wsdl.

At the moment, I have multiple methods similar to that below (including the one below).

Using a property, TaxYear to determine which wsdl to actually reference: "Service2015" or "Service2016". I am passing in generic objects representing the objects from the wsdl, and passing in a ref parameter for those objects which I use in a parent method.

Refacotring like this, imposes a LOT of bloat, and I can't help but think there has to be a better way to do what I'm trying to do.

Is there a better way at doing this using C#, or is this the best and most inconvenient way of doing what I need to accomplish.

private static void RetrieveRequestObject(ref object objRequest, object objBusinessHeader, object objSecurityHeader, object objManifestHeader, object objFormData)
{
    if (TaxYear.Equals(2015))
    {
        objRequest = new Service2015.BulkRequestTransmitterRequest()
        {
            ACABusinessHeader = (Service2015.ACABulkBusinessHeaderRequestType)objBusinessHeader,
            Security = (Service2015.SecurityHeaderType)objSecurityHeader,
            ACATransmitterManifestReqDtl = (Service2015.ACATrnsmtManifestReqDtlType)objManifestHeader,
            ACABulkRequestTransmitter = (Service2015.ACABulkRequestTransmitterType)objFormData
        };
    }
    else if (TaxYear.Equals(2016))
    {
        objRequest = new Service2016.BulkRequestTransmitterRequest()
        {
            ACABusinessHeader = (Service2016.ACABulkBusinessHeaderRequestType)objBusinessHeader,
            Security = (Service2016.SecurityHeaderType)objSecurityHeader,
            ACATransmitterManifestReqDtl = (Service2016.ACATrnsmtManifestReqDtlType)objManifestHeader,
            ACABulkRequestTransmitter = (Service2016.ACABulkRequestTransmitterType)objFormData
        };
    }
}

Solution

  • After some correspondence with the Web Service owners, it turns out that I do not have to juggle different endpoints or year-to-year versions of the .wsdl files. Transmission occurs on the same endpoint regardless of year, and in order to validate the schema between years, the owners of the Web Service check the TaxYear element in the Transmission Manifest in order to determine the schema to validate against.

    To accommodate this, I have 2 separate XML "template" documents, one for each required Tax Year: 2015 and 2016. My application will then determine which template to use based on the data we are attempting to transmit (via the value for the TaxYear used in the Manifest).

    I created these templates from hand based on all of the elements that could be in the Form Data XML. Any repeating element groups only have a singular instance. Multiple instances of these are created within the application.

    My application reads the XML Template and replaces the dummy values found within with values retrieved from our data. I remove any unused or invalid elements from the XML dictated by the schema version; and create/clone any elements we have to repeat (such as Part 3 of the 1095-C and 1094-C Forms). So far, this approach appears to be working quite well through initial testing.