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 9096513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:52:19+00:00 2026-06-16T23:52:19+00:00

I have a very basic WCF service that receives uploaded documents. When defined like,

  • 0

I have a very basic WCF service that receives uploaded documents. When defined like, it works perfectly:

<ServiceContract()>
Public Interface ITransferService

    <OperationContract()>
    <FaultContractAttribute(GetType(MyProcessingFault))>
    Function UploadFile(ByVal request As RemoteFileInfo) As MyWebMethodResult

End Interface

<MessageContract()>
Public Class RemoteFileInfo
    Implements IDisposable

    <MessageHeader(MustUnderstand:=True)>
    Public FileName As String

    <MessageHeader(MustUnderstand:=True)>
    Public Length As Long

    <MessageBodyMember()>
    Public FileByteStream As System.IO.Stream

    Public Sub Dispose() Implements IDisposable.Dispose
        If FileByteStream IsNot Nothing Then
            FileByteStream.Close()
            FileByteStream = Nothing
        End If
    End Sub

End Class

However, I was a bit confused about using MessageContractAttribute, and most authors suggest keeping things simple with a DataContract instead. When I change the above to the following however, like this…

<ServiceContract()>
Public Interface ITransferService

    <OperationContract()>
    <FaultContractAttribute(GetType(MyProcessingFault))>
    Function UploadFile(ByVal request As RemoteFileInfo) As MyWebMethodResult

End Interface

<DataContract()>
Public Class RemoteFileInfo
    Implements IDisposable

    <DataMember>
    Public FileName As String

    <DataMember>
    Public Length As Long

    <DataMember()>
    Public FileByteStream As System.IO.Stream

    Public Sub Dispose() Implements IDisposable.Dispose
        If FileByteStream IsNot Nothing Then
            FileByteStream.Close()
            FileByteStream = Nothing
        End If
    End Sub

End Class

I get the following WCF exception when I try to upload to the service:

Type ‘System.IO.FileStream’ with data contract name
‘FileStream:http://schemas.datacontract.org/2004/07/System.IO&#8217; is not
expected

Researching this, I read that streams cannot be serialized, however, surely this must be incorrect for the first example to work? Is it possible to use a FileStream with a DataContract, or should I not bother even attempting this approach?

  • 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-16T23:52:20+00:00Added an answer on June 16, 2026 at 11:52 pm

    DataContract messages serialize in a different way than MessageContract messages. Having a Stream member (thus allowing streaming) must be done using MessageContract, wcf then understands it is inteded for streaming and does not try to perform standard serialization.

    See http://msdn.microsoft.com/en-us/library/ms733742.aspx for more info:

    You should not be using System.IO.Stream derived types inside of data
    contracts. Stream data should be communicated using the streaming
    model, explained in the following “Streaming Data” section.

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

Sidebar

Related Questions

I have some very basic semaphore code that works great on Linux, but cannot
Consider the following very basic WCF service implementation: public enum TransactionStatus { Success =
I have added a very basic WCF Service to my windows phone application. When
I have made a REST Web service, that works with Visual Studios WCF Test
I have a very basic mysql table called memberships, that tracks which people belong
I have a very basic doubt regarding the method that gets executed when app
I have a very basic data class that is subclassed from NSObject. I declare
I have a WCF restful service that I'm trying to upload an image to.
I have very basic class: class Customer { protected $id; protected $customer; public function
I have a .Net service running on IIS 6 and WCF that I want

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.