Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8414163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:05:46+00:00 2026-06-10T01:05:46+00:00

I am writing a WCF client to a SOAP service that returns a mime

  • 0

I am writing a WCF client to a SOAP service that returns a mime multi-part result with binary data (actually, a PDF file). It uses a custom message encoder.

The service doesn’t seem to mind if I make the request a single-part format, so I am able to get a result back. There are two problems with the result from what I can see:

  • It only seems to return the first part of the multi-part message.
  • The data I get back cannot be decoded by my custom encoder.

I have tried utilizing MTOM binding, but that messes up the request. It fails to add the “boundary” parameter in the content-type, so the server cannot understand the request.

I think what I want is a basic text SOAP request, but a response decoded MTOM-style. I have no idea how to set that up, however.

The closest solution I have found is this: http://blogs.msdn.com/b/carlosfigueira/archive/2011/02/16/using-mtom-in-a-wcf-custom-encoder.aspx

But it seems like a very invasive change to my project.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:05:47+00:00Added an answer on June 10, 2026 at 1:05 am

    I figured this out. First of all, I was incorrect when I said that I was only getting the first part of the multi-part message using the MTOM encoder; I was getting the whole thing. I was looking at it in the debugger and the bottom must have gotten clipped in the debug viewer. Chalk it up to my inexperience manually looking at and deciphering multi-part messages.

    To the second point, all I had to do was use the MTOM encoder when the Content-Type was multipart/related and everything worked just fine. If you read the referenced article above, it’s all about dynamically detecting whether the message is multipart or regular text, and choosing the proper encoder based on that. Essentially, it’s a custom encoder that has both a text encoder and MTOM encoder built into it, and switches back and forth based on the content-type of the incoming message.

    Our project requires some post processing of the response message before it’s handed off to the main program logic. So, we get the incoming SOAP content as an XML string, and do some XML manipulation on it.

    This is a slight departure from the solution recommended in the article. All that’s required in the article’s solution is reading the message using the right encoder into a System.ServiceModel.Channels.Message, and returning that. In our solution, we need to interrupt this process and do the post-processing.

    To do that, implement the following in your custom encoder:

    public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
    {
        //First, get the incoming message as a byte array
        var messageData = new byte[buffer.Count];
        Array.Copy(buffer.Array, buffer.Offset, messageData, 0, messageData.Length);
        bufferManager.ReturnBuffer(buffer.Array);
        //Now convert it into a string for post-processing.  Look at the content-type to determine which encoder to use.
        string stringResult;
        if (contentType != null && contentType.Contains("multipart/related"))
        {
            Message unprocessedMessageResult = this.mtomEncoder.ReadMessage(buffer, bufferManager, contentType);
            stringResult = unprocessedMessageResult.ToString();
        }
        else {
            //If it's not a multi-part message, the byte array already has the complete content, and it simply needs to be converted to a string
            stringResult = Encoding.UTF8.GetString(messageData);
        }
        Message processedMessageResult = functionToDoPostProccessing(stringResult);
        return processedMessageResult;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data model: I am writing a WCF service that needs
I am writing the client side for a WCF service that supports both synchronous
I'm writing a .NET app that calls a WCF Data Service that requires authentication
I am currently writing a WCF client for a Java web service that is
I'm writing a WCF REST Service that has a mobile client. The mobile client
I am writing WCF service that uses wsHttpBinding binding, which is not hosted in
I have a WCF service that is responsible for writing a log file. I
I'm a bit lost concerning WCF Server authentication... I'm writing a WCF service that
I'm writing a PHP client to a C#/WCF web service. The parameters for some
I am writing a WCF client for a service (not WCF). Getting an error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.