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

  • SEARCH
  • Home
  • 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 9004089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:49:24+00:00 2026-06-16T00:49:24+00:00

I am attempting to upload a file through a Silverlight client using the following

  • 0

I am attempting to upload a file through a Silverlight client using the following MessageContract:

[MessageContract]
public class CategoryClientFileTransferMC : IDisposable
{
    /// <summary>
    /// CategoryID - Category identity.
    /// </summary>
    [MessageHeader(MustUnderstand = true)]
    public int CategoryID;

    /// <summary>
    /// ID - File identifier.
    /// </summary>
    [MessageHeader(MustUnderstand = true)]
    public string ID;

    /// <summary>
    /// Length - File length in bytes.
    /// </summary>
    [MessageHeader(MustUnderstand = true)]
    public long Length;

    /// <summary>
    /// FileByteStream - File stream.
    /// </summary>
    [MessageBodyMember(Order = 1)]
    public Stream FileByteStream;

    /// <summary>
    /// Dispose the contract.
    /// </summary>
    public void Dispose()
    {
        if (FileByteStream != null)
        {
            FileByteStream.Close();
            FileByteStream = null;
        }
    }
}

My problem is that the generated operation method on the client only takes a single argument; a byte array called FileByteStream. In other (non-Silverlight) clients I’ve created it asks for the MemberHeader fields as well. Without specifying these headers, the server has no idea what to do with the file. How can I set these headers when I call the operation?

Also, is there a better way to upload a file from a Silverlight client? This has been a huge headache.

Thanks.

  • 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-16T00:49:26+00:00Added an answer on June 16, 2026 at 12:49 am

    The Silverlight subset of the WCF client does not support the [MessageHeader] attribute. You can still set message headers, but it’s not as straightforward as in other platforms. Basically, you’ll need to set the headers using the operation context, prior to making the call, like in the example below:

    var client = new SilverlightReference1.MyClient();
    using (new OperationContextScope(client.InnerChannel))
    {
        string contractNamespace = "http://tempuri.org/";
        OperationContext.Current.OutgoingMessageHeaders.Add(
            MessageHeader.CreateHeader("CategoryId", contractNamespace, 1));
        OperationContext.Current.OutgoingMessageHeaders.Add(
            MessageHeader.CreateHeader("ID", contractNamespace, "abc123"));
        OperationContext.Current.OutgoingMessageHeaders.Add(
            MessageHeader.CreateHeader("Length", contractNamespace, 123456L));
        client.UploadFile(myFileContents);
    }
    

    Where contractNamespace is the XML namespace for the message header fields (IIRC they default to the same as the service contract). You can use Fiddler and something like the WCF Test Client to see which namespace is used there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to upload multiple files from a Silverlight client directly to Amazon
I'm running IIS 6.1 and I am attempting to upload a file through the
I am attempting to let a client upload a file to my server in
I’m attempting to upload a file to AS400 using C#. The structure is: ftp_server_ip_address/library/table
We're attempting to upload a file using a hidden iframe and the script runs
I am attempting to upload a video file in chunks using PHP. (and we
I'm attempting to upload a file asynchronously using HTTP POST and jQuery, but I'm
When attempting a file upload to an Alfresco Server using ssl the server logs
I am attempting to use FTP in Powershell to upload a file. I am
I'm attempting to upload a file into a jsp and then use the file

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.