1

I am getting following error while I am consuming client web service.

Error: The content type text/xml;charset=utf-8 of the response message does not match the content type of the binding (application/soap+msbin1+gzip). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.

The first 807 bytes of the response were:

' soapenv:Client The request message must be sent using HTTP compression (RFC 1952 - GZIP). Please review the transmission instructions outlined in Section 5 of the AIR Submission Composition and Reference Guide located at https://www.irs.gov/for-Tax-Pros/Software-Developers/Information-Returns/Affordable-Care-Act-Information-Return-AIR-Program, correct any issues, and try again. TPE1112 '.==========================Error: System.Net.WebException: The remote server returned an error: (500) Internal Server Error. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

I know there are many articles are available about this error but I am unable to get solution or hint, how to solve this issue?

Basically Client has provided WSDL file and I have added it as "Service References" into my console application.

Here is my config file

<bindings>
  <customBinding>
    <binding name="BulkRequestTransmitterBinding"  >
      <binaryMessageEncoding compressionFormat="GZip" />
      <httpsTransport/>
    </binding>
  </customBinding>
</bindings>
<client>
  <endpoint address="MYENDPOINTURL"
      binding="customBinding" 
      bindingConfiguration="BulkRequestTransmitterBinding"
      contract="CONTRACTNAME" 
      name="BulkRequestTransmitterPort" />
</client>
M005
  • 824
  • 1
  • 9
  • 25

2 Answers2

3

To start out, you need to download this sample encoder from Microsoft

Set it up and add it as a project to your solution. Afterwards you need to make some tweaks.

  1. First you need to change the content type to be"text/xml" instead of "application/x-gzip". by changing

    class GZipMessageEncoder : MessageEncoder
    {
    static string GZipContentType = "application/x-gzip";
    

    to

    static string GZipContentType = "text/xml";
    
  2. Right before transmitting you also need to change the content encoding header, this blog post describes it in more detail but the code is here:

    using (new OperationContextScope(transmitter.InnerChannel))
    {
    // Add a HTTP Header to an outgoing request
    HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
    requestMessage.Headers["Content-Encoding"] = "gzip";
    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
    
    var response = transmitter.BulkRequestTransmitter(
        securityHeader,
        security,
        ref businessHeader,
        transmitterManifestReqDtl,
        transmitterType);
    ParseSubmitResponse(response);
    }
    
  3. The IRS, while demanding you send everything compressed, responds in uncompressed format (at least to the transmitter section, who knows what they decided to do with the status portion) so the decompression routine needs to be disabled, it is located in

    ZipEncoder.CZipMessageEncoderFactory.GZipMessageEncoder.DecompressBuffer
    

    You just need to comment out the using statement and swap

    int bytesRead = gzStream.Read(tempBuffer, 0, blockSize);
    

    with

    int bytesRead = memoryStream.Read(tempBuffer, 0, blockSize);
    
  4. Next, You need to change the inner message encoding message version to be compatible with the IRS. So in

    GZipEncoder.GZipMessageEncodingElement.ApplyConfiguration
    

    You need to change the constructor for TextMessageEncodingBindingElement to this:

    binding.InnerMessageEncodingBindingElement =
        new TextMessageEncodingBindingElement(MessageVersion.Soap11WSAddressing10, Encoding.UTF8);
    
  5. With this, you are almost ready, you just need to add stuff to app.config You need to add the following section (the Service model is tag for reference of which section):

    <system.serviceModel>
      <extensions>
        <bindingElementExtensions>
          <add name="gzipMessageEncoding" type="GZipEncoder.GZipMessageEncodingElement, GZipEncoder, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" />
        </bindingElementExtensions>
      </extensions>
    
  6. Now you can make your binding look like this:

    <binding name="BulkRequestTransmitterBinding">
      <gzipMessageEncoding innerMessageEncoding="textMessageEncoding" />
      <httpsTransport />
    </binding>
    

With that, your code should successfully transmit to the IRS.

0

I am in the same boat as both of you in regards to the inability to simply comment. Great explanation on transmitting to the IRS. It seems there are a few of us working on this site working on this same project for our respective entities.

However, I am running into the following error, and am having trouble determining the next steps to resolve it. I am receiving this error when instantiating the BulkRequestTransmitterPortTypeClient to a new object so that I can add the Content-Encoding to the header and send the request to the IRS.

An unhandled exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll

Additional information: The type 'GZipEncoder.GzipMessageEncodingElement, GZipEncoder' registered for extension 'gzipMessageEncoding' could not be loaded.

  • I have created a new Project in my solution and created the three class files from the Encoding sample.
  • I made the changes you outlined to my code.
  • Added this project as a reference in my Client application.
  • In my client application, the gzipMessageEncoding app.config entry is underlined, but from other posts I have read, this is okay.
  • I have what I believe are the appropriate <extensions><bindingElementExtensions> and <metadata><policyImporters><extension> entries in my app.config.

Answer-Edit
To overcome the error I was having, I found this post which led me to use the following code to output the type strings that I needed to add to the app.config. I copied the strings output by these commands into the app.config and that got me past the error above.

Console.WriteLine(typeof(GZipEncoder.GZipMessageEncodingElement).AssemblyQualifiedName);
Console.WriteLine(typeof(GZipEncoder.GZipMessageEncodingBindingElementImporter).AssemblyQualifiedName);

app.config entries

<system.serviceModel>
  <extensions>
    <bindingElementExtensions>
      <add name="gzipMessageEncoding" type="GZipEncoder.GZipMessageEncodingElement, GZipMessageEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </bindingElementExtensions>
  </extensions>
  <client>
    <metadata>
      <policyImporters>
        <extension type="GZipEncoder.GZipMessageEncodingBindingElementImporter, GZipMessageEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </policyImporters>
    </metadata>
  </client>
  <bindings>
    <customBinding>
      <binding name="BulkRequestTransmitterBinding">
        <gzipMessageEncoding innerMessageEncoding="textMessageEncoding" />
        <httpsTransport />
      </binding>
    </customBinding>
  </bindings>
</system.serviceModel>

I still receive a schema validation warning on the gzipMessageEncoding element, but a lot of things I've seen have said that is supposed to be the case. So for now, I'm going to ignore it.

Request Submission

// Called from the main method.
// 'request' is the BulkRequestTransmitterRequest object where the BusinessHeader, 
// Manifest, Security, and FormData are set.
ACABulkRequestTransmitterResponseType response = SubmitRequest(request).ACABulkRequestTransmitterResponse;

private static BulkRequestTransmitterResponse SubmitRequest(BulkRequestTransmitterRequest request)
{
    // Create a new instance of the Web Service client object.
    BulkRequestTransmitterPortTypeClient client = new BulkRequestTransmitterPortTypeClient("BulkRequestTransmitterPort");

    using (new OperationContextScope(client.InnerChannel))
    {
        // Add a HTTP Header to an outgoing requqest.
        HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();

        requestMessage.Headers["Content-Encoding"] = "gzip";
                            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;

        return client.BulkRequestTransmitter(request);
    }
}

Next onto the next fault which I am receiving on the TransmitterRequest and StatusRequest:

Additional information: The WS Security Header in the message is invalid.

Community
  • 1
  • 1
Russ
  • 678
  • 8
  • 26