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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:44:11+00:00 2026-06-18T00:44:11+00:00

So simple in theory, but I have never been a wiz at WCF configuration.

  • 0

So simple in theory, but I have never been a wiz at WCF configuration. What I am trying to do is this: I have a WCF method that matches this signature:

[OperationContract]
[WebInvoke(Method = "POST")]
Stream PostPackets(Stream rawPackets);

All I really care about is getting a byte array from an Android/iPhone/Blackberry/any other type of device, to my wcf service, process the array and then send back a different array of bytes. For all I care, it could look like:

[OperationContract]
[WebInvoke(Method = "POST")]
byte[] PostPackets(byte[] rawPackets);

Though all examples I see seem to use Stream.

I have read many different articles and posts with no straight answer on how to do this outside the context of a file transfer (which is not my intention). Here are the problems I am facing:

1- I assume I need to use webHttpBinding to make this service RESTful. Is this right? If so, can you point me to a sample configuration?

2 – (And this is absolutely what I cannot find anywhere!) I need to be sure that this is not going to be a huge pain for the device developers to consume. Can you show me examples of both Android and iPhone devices consuming a RESTful service AND (very important) how they would send a byte array to my service?

Please forgive my noobiness… WCF configuration is one of those things I don’t get to do every day. Once I get my configuration figured out, I generally move on and never have to touch it until my next project (which could be a very long time). Please help!

UPDATE

My colleague suggested that we use http handlers instead of wcf. Do we really have to resort to that?
e.g.:

public void ProcessPackets (HttpContext context) 

UPDATE 2:

I am wondering, is there any way to do this without JSON? Is there any downside/alternative to posting the array as type “text/plain”?

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

    In the end the solution was as follows. (It was quite simple indeed)

    Service side:

    [ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate="TestMethod/")]
        Stream TestMethod(Stream input);
    
    }
    
    public class MyService: IMyService
    {
        Stream IMyService.TestMethod(Stream input)
        {
            byte[] buffer = new byte[10000];
            int bytesRead, totalBytesRead = 0;
            this.currentResponseOffset = 0;
            do
            {
                bytesRead = input.Read(buffer, 0, buffer.Length);
                totalBytesRead += bytesRead;
            } while (bytesRead > 0);
    
            input.Close();
    
            return new MemoryStream(buffer, 0, totalBytesRead);
        }
    }
    

    With a configuration that looks like:

    <services>
      <service name="MyService" >
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/MyService/" />
            <add baseAddress="net.tcp://localhost:4504/Design_Time_Addresses/MyService/" />
          </baseAddresses>
        </host>
        <endpoint address="MyTCPService" binding="netTcpBinding" contract="IMyTCPService">
        </endpoint>
    
        <endpoint address="MyHTTPService" binding="webHttpBinding" behaviorConfiguration="web" contract="IMyService"></endpoint>  
    
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <endpoint address="mex"  binding="mexHttpBinding" contract="IMetadataExchange"/>
        <!--<endpoint binding="mexHttpsBinding" bindingConfiguration="" contract="IMetadataExchange" />-->
      </service>
    </services>
    <behaviors>
       <endpointBehaviors>
        <behavior name="web">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    

    I was able to test it out with a .net client, though the whole point of this post was to know how to make it cross platform. I guess we will see soon enough! Thanks @I4V for your help, it was much appreciated.

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

Sidebar

Related Questions

This is simple in theory, but difficult for me to figure out. I have
We have a relatively simple assignment that I understand in theory but I think
This is a simple question from algorithms theory. The difference between them is that
This is a very simple task in every language I have ever used, but
OK, this should in theory be simple, but I've tried several things like parent
This will be a bit abstract but I have a method like this: private
I wrote a simple program to test a theory that finally block will always
Simple issue but I'm at a loss to debug this further. I followed the
Simple question - How do I convert a string that has been through parseInt
I feel like I should know this but I've been stumped for hours now

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.