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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:19:02+00:00 2026-05-24T06:19:02+00:00

I am in the process of developing a WCF service that needs to take

  • 0

I am in the process of developing a WCF service that needs to take in an image and 2 parameters. One being an int type, the other a string array. So this would be easy enough if it were only 1 parameter to send up, along with the image:

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "UploadImages/{imageID}")]
public void UploadImages(int imageID, Stream image)
{                       
}

Now, in this scenario the image is in the body of the post. What if the consumer of the service needs to pass up a third piece of data, how does that look and work in WCF?

  <system.serviceModel>
    <client>
    </client>
    <bindings>
      <webHttpBinding>
        <binding name="webHttpBindingStreamed" transferMode="Streamed"></binding>
      </webHttpBinding>      
    </bindings>
    <services> 
      <service name="ImageService">
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="MyWebHttpBehavior"  name="ImageServiceWebBinding" contract=IImageService" />
      </service>
    </services>
    <behaviors>      
      <endpointBehaviors>          
        <behavior name="MyWebHttpBehavior">
          <customWebHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add name="customWebHttp" type="CustomHttpBehaviorExtensionElement, ImageUploader" />
      </behaviorExtensions>
    </extensions>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  • 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-05-24T06:19:03+00:00Added an answer on May 24, 2026 at 6:19 am

    You can pass the additional parameters in the URI as well, like in the example below. Or you can pass them as HTTP headers and fetch them using the WebOperationContext.Current.IncomingRequest.Headers property.

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "UploadImages/{fileName}?imageId={imageID}")]
    public void UploadImages(int imageID, string fileName, Stream image)
    {                       
    }
    

    Update

    Even if the parameter type is an array, you can also pass it in the query string – but you’ll need to provide a QueryStringConverter which can decode that type. The example below shows that.

    public class StackOverflow_6905108
    {
        [ServiceContract]
        public class Service
        {
            [OperationContract]
            [WebInvoke(Method = "POST", UriTemplate = "UploadImages/{fileName}?array={array}")]
            public void UploadImages(int[] array, string fileName, Stream image)
            {
                Console.WriteLine("Array:");
                foreach (var item in array) Console.Write("{0} ", item);
                Console.WriteLine();
            }
        }
        public static void SendPost(string uri, string contentType, string body)
        {
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);
            req.Method = "POST";
            req.ContentType = contentType;
            Stream reqStream = req.GetRequestStream();
            byte[] reqBytes = Encoding.UTF8.GetBytes(body);
            reqStream.Write(reqBytes, 0, reqBytes.Length);
            reqStream.Close();
    
            HttpWebResponse resp;
            try
            {
                resp = (HttpWebResponse)req.GetResponse();
            }
            catch (WebException e)
            {
                resp = (HttpWebResponse)e.Response;
            }
    
            Console.WriteLine("HTTP/{0} {1} {2}", resp.ProtocolVersion, (int)resp.StatusCode, resp.StatusDescription);
            foreach (string headerName in resp.Headers.AllKeys)
            {
                Console.WriteLine("{0}: {1}", headerName, resp.Headers[headerName]);
            }
            Console.WriteLine();
            Stream respStream = resp.GetResponseStream();
            Console.WriteLine(new StreamReader(respStream).ReadToEnd());
    
            Console.WriteLine();
            Console.WriteLine(" *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* ");
            Console.WriteLine();
        }
        class MyQueryStringConverter : QueryStringConverter
        {
            QueryStringConverter originalConverter;
            public MyQueryStringConverter(QueryStringConverter originalConverter)
            {
                this.originalConverter = originalConverter;
            }
            public override bool CanConvert(Type type)
            {
                return type == typeof(int[]) || base.CanConvert(type);
            }
            public override object ConvertStringToValue(string parameter, Type parameterType)
            {
                if (parameterType == typeof(int[]))
                {
                    return parameter.Split(',').Select(x => int.Parse(x)).ToArray();
                }
                else
                {
                    return base.ConvertStringToValue(parameter, parameterType);
                }
            }
        }
        public class MyWebHttpBehavior : WebHttpBehavior
        {
            protected override QueryStringConverter GetQueryStringConverter(OperationDescription operationDescription)
            {
                return new MyQueryStringConverter(base.GetQueryStringConverter(operationDescription));
            }
        }
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            host.AddServiceEndpoint(typeof(Service), new WebHttpBinding(), "").Behaviors.Add(new MyWebHttpBehavior());
            host.Open();
            Console.WriteLine("Host opened");
    
            SendPost(baseAddress + "/UploadImages/a.txt?array=1,2,3,4", "application/octet-stream", "The file contents");
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a WCF service that accepts parameters in JSON. I cant' figure out
I am in the process of developing a WCF Restful Service. One of the
WCF Service I am developing a WCF Service and it needs to communicate with
We're in the process of developing a WCF REST web service which just receives
In the process of developing my first WCF service and when I try to
I am developing a C++ application that needs to process large amount of data.
I am in the process of developing a web application that consists visually of
I'm in the process of developing a Silverlight custom control that hosts a Flash
I'm in the process of developing a website that makes use of JQuery's superfish.
I am developing one product and there are 4 separate projects, in that I

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.