WCF Service Generated Proxy Class Exposing Function as ByRef Sub

I have a WCF Service exposing a single contract and operation:

<ServiceContract(Namespace:="ImageSystem")> _
Public Interface IUploadService

    <OperationContract()> _
    Function UploadFile(ByVal file As ImageUpload) As ImageUpload

End Interface

The function both receives and returns an "ImageUpload" which is defined as such:

<MessageContract()> _
Public Class ImageUpload

    <MessageHeader()> _
    Public Property ImageID() As Nullable(Of Long)

    <MessageHeader()> _
    Public Property ImageTypeID() As Long

    <MessageHeader()> _
    Public Property IncludeInGallery() As Boolean

    <MessageHeader()> _
    Public Property OriginalFileName() As String

    <MessageHeader()> _
    Public Property ErrorDescription() As String

    <MessageBodyMember()> _
    Public Data As System.IO.Stream

End Class

The endpoints are defined as follows (not sure this matters too much but just in case):



        <binding name="netTcpStreamBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
          receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
          transferMode="Streamed" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
          maxBufferSize="20971520" maxConnections="10" maxReceivedMessageSize="20971520">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None" />

      <endpoint address="net.tcp://localhost:809/UploadService" binding="netTcpBinding"
        bindingConfiguration="netTcpStreamBinding" contract="UploadService.Local.IUploadService"
          <dns value="localhost" />




        <binding name="netTcpStreamBinding" transferMode="StreamedRequest" maxBufferSize="20971520"
                 maxReceivedMessageSize="20971520" >
          <security mode="None"/>
      <service behaviorConfiguration="UploadServiceBehaviour"
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpStreamBinding"
            <dns value="localhost" />
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
            <add baseAddress="net.tcp://localhost:809/UploadService" />
        <behavior name="UploadServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the 
          metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="false"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  
          Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>

My problem is that the proxy class generated by adding a service reference to the client, is generating a sub (void function) instead of the function I was expecting.

What's more, the generated sub doesn't accept my message contract as in/out parameters, instead it lists the message contracts' members.

I.e, I would expect the auto-generated proxy class to have the following signature:

Public Function UploadFile(ByVal file As ImageUpload) As ImageUpload

Instead, it's generating:

    Public Sub UploadFile(ByRef ErrorDescription As String, ByRef ImageID As System.Nullable(Of Long), ByRef ImageTypeID As Long, ByRef IncludeInGallery As Boolean, ByRef OriginalFileName As String, ByRef Data As System.IO.Stream)
        Dim inValue As UploadService.Local.ImageUpload = New UploadService.Local.ImageUpload()
        inValue.ErrorDescription = ErrorDescription
        inValue.ImageID = ImageID
        inValue.ImageTypeID = ImageTypeID
        inValue.IncludeInGallery = IncludeInGallery
        inValue.OriginalFileName = OriginalFileName
        inValue.Data = Data
        Dim retVal As UploadService.Local.ImageUpload = CType(Me,UploadService.Local.IUploadService).UploadFile(inValue)
        ErrorDescription = retVal.ErrorDescription
        ImageID = retVal.ImageID
        ImageTypeID = retVal.ImageTypeID
        IncludeInGallery = retVal.IncludeInGallery
        OriginalFileName = retVal.OriginalFileName
        Data = retVal.Data
    End Sub

This subsequently leads to stream casting issues, because the generated function allows me to pass a memory stream as an input (which works correctly when passed through to the service), but instead of passing me back a new stream for the response, it attempts to cast the MessageBodyStream received from the service into my memory stream.

This is, in some ways similar to other posts but as you can see, there are no enums involved in my contracts - presence of Enums caused strange proxy class generation is marked as the answer in the similar post.

Is there anywhere I configure the proxy behaviour to use the contracts I've specified? Clearly I'm within a dev/test environment currently, but when this eventually goes to production it will be memory and file streams passed to the service, and the returned stream can be in any format to be honest, I intend to treat it as the abstract stream class. The only way round this I can see right now is to change my in stream to be the same as the anticipated out stream, but surely there is a better way?


Total idiot. I hadn't checked the box in the service reference configuration for "Always Generate message Contracts".

Once checked my proxy class signatures were changed to the expected signatures in my OP.

Apologies for the hub-bub ^^

Need Your Help

Pass request parameters through FacesContext

jsf-2 parameter-passing actionlistener managed-bean

I moved from JSF 1.2 to JSF 2.0 and it seems I missed something during the switch. I have following scenario:

Postback upon clicking a row in a gridview

c# asp.net gridview postback web-controls

I'm using the code found here to make my gridview have clickable rows. The code for that is:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.