error in POST REST webservice, stream must have single parameter

I am uploading a file via a web service using REST and receiving an error message because I have multiple parameters in my POST WEBINVOKE.

this is error message...

For request in operation transferData to be a stream the operation must have a single parameter whose type is Stream.

I've read THOUSANDS of tutorials on this and I see other people have the same problem however I don't see a real solution for me.

any ideas on what I am doing wrong?

Here is my code

namespace EngineAppServiceV001
{
the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{


    [OperationContract]
    [WebGet(UriTemplate = "/DoWork/{cid}",
      ResponseFormat = WebMessageFormat.Json,
      RequestFormat = WebMessageFormat.Json,
      BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    DataSet DoWork(string cid);

    [OperationContract]
    [WebInvoke(Method = "POST",
        UriTemplate = "/UploadFile/{fileName}")]
    string transferData(string filename, Stream fileStream);


}

Open in new window


here is my web.config

<bindings>
  <basicHttpBinding>
    <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
        maxArrayLength="16348" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="ServiceWebBindingName" transferMode="Streamed" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <security mode="None"></security>
    </binding>
  </webHttpBinding>
</bindings>

<services>
  <service name="EngineAppServiceV001.Service1" behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" contract="EngineAppServiceV001.IService1" behaviorConfiguration="web" />
  </service>
</services>

<behaviors>

  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>

  <endpointBehaviors>
    <behavior name="web">
      <webHttp />
    </behavior>
  </endpointBehaviors>

</behaviors>

Open in new window

Stephen ForeroAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Phil DavidsonCommented:
I think it would be educational to attempt to upload a file that is a .json file.  If that works, that might tell you something.  If it doesn't, I'm curious what the error message would be.  If it is the same error, I would try to re-write the webinvoke and transferData functions in the C#.
Phil DavidsonCommented:
I think it would be helpful to troubleshoot the problem by trying to upload a file that is a .json file.  If that works, that might tell you something.  If it doesn't, I'm curious what the error message would be.  If it is the same error, I would try to re-write the webinvoke and transferData functions in the C# code.
Stephen ForeroAuthor Commented:
Thanks Phil.  I ended up created a separate service to make this work.  Then in the web.config added basicHttpBindings... not sure if this is REST or something else but it is working.  Either way just bought a book to do some reading on the concepts behind all of this.

    [ServiceContract]
    public interface IService2
    {

        [OperationContract]
        void UploadFile(RemoteFileInfo request);

        [OperationContract]
        string sqlBulkUpload(string fileName);

        [OperationContract]
        string addAccountID(string fileName);

        [OperationContract]
        string createPrimeOpenPositions(string fileName);

        [OperationContract]
        string deleteTempFile(string fileName);



        [OperationContract]
        string sqlBulkUpload_TOPDAY(string fileName);

        [OperationContract]
        string addAccountID_TOPDAY(string fileName);

        [OperationContract]
        string createPrimeTopday(string fileName);

    }



    [MessageContract]
    public class RemoteFileInfo : IDisposable
    {
        [MessageHeader(MustUnderstand = true)]
        public string FileName;

        [MessageHeader(MustUnderstand = true)]
        public long Length;

        [MessageBodyMember(Order = 1)]
        public System.IO.Stream FileByteStream;

        public void Dispose()
        {
            if (FileByteStream != null)
            {
                FileByteStream.Close();
                FileByteStream = null;
            }
        }

    }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stephen ForeroAuthor Commented:
I ended up using a new service to complete the task using basicHttpBinding
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
REST

From novice to tech pro — start learning today.