none
WCF Large size request data handling concurrently RRS feed

  • Question

  • I have a self hosted WCF service for handling HTTP POST request.
    My WCF service method will handle 2 types of request (1. getting data, 2. Do some action with given data).

    My scenario :
    1. Started Action request with large amount of data. : during the starting of that action do some processing.
    2. client reads some results.
    3. sending the remaining data for the previous action.

    I implemented this using 'TcpListener' it is working.

    Problem:
    when i try to implement this scenario using WCF, i have got the 'Bad request' during the first action request.

    [ServiceContract]
        public interface ITest
        {
            [OperationContract, WebInvoke(Method = "POST", UriTemplate = "{*pathname}")]
            Stream GetResponse(string pathname, Stream requestBody);
        }

        [ServiceBehavior(AddressFilterMode = AddressFilterMode.Exact, ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.Single, UseSynchronizationContext = false, IncludeExceptionDetailInFaults = true)]
        class TestService : ITest
        {
            public Uri BaseUri { get; private set; }
            public IPAddress Address { get; private set; }
            public Int32 Port { get; private set; }
            public bool IsStarted { get { return Host != null; } }
            public ServiceHost Host { get; private set; }

            public TestService()
            {
            }

            public TestService(IPAddress ipAddress, int port)
            {
                if (ipAddress == null) { throw new ArgumentNullException("Address"); }
                this.Address = ipAddress;
                this.Port = port;
                this.BaseUri = new Uri(string.Format("http://{0}:{1}", this.Address, this.Port));
            }

            public void Start()
            {
                if (IsStarted) { throw new InvalidOperationException("Service is already started."); }
                Host = CreateServiceHost();
                Host.Open();
            }

            public void Stop()
            {
                if (!IsStarted) { throw new InvalidOperationException("Service is already stopped."); }
                Host.Close();
                Host = null;
            }

            private ServiceHost CreateServiceHost()
            {
                ServiceHost host = new ServiceHost(typeof(TestService), this.BaseUri);

                WebHttpBinding webhttpBinding = new WebHttpBinding();
                webhttpBinding.MaxBufferPoolSize = int.MaxValue;
                webhttpBinding.MaxBufferSize = int.MaxValue;
                webhttpBinding.MaxReceivedMessageSize = int.MaxValue;

                CustomBinding binding = new CustomBinding(webhttpBinding);
                WebMessageEncodingBindingElement webEncoding = binding.Elements.Find<WebMessageEncodingBindingElement>();
                webEncoding.ContentTypeMapper = new RawMapper();

                host.AddServiceEndpoint(typeof(ITest), binding, new Uri(this.BaseUri.AbsoluteUri)).Behaviors.Add(new WebHttpBehavior());

                return host;
            }

            public Stream GetResponse(string pathname, Stream requestBody)
            {
                Stream response=null;
                /**************     Process 'requestBody'    **************/

                //requestBody contains "MY_ACTION"
                //{
                //      Find the start delimeter from response : START processing
                //      Find the end delimeter from response : STOP processing
                //}

                //requestBody contains "GET_MY_DATA"
                //{
                //      Find data and send response
                //}
                return response;
            }
        }

        public class RawMapper : WebContentTypeMapper
        {
            public override WebContentFormat GetMessageFormatForContentType(string contentType)
            {
                return WebContentFormat.Raw;
            }
        }

    Any help/guidance would be great as I'm really stuck on this.


    sujithsb

    Monday, March 3, 2014 1:29 PM

All replies

  • Hi,

    For your question, first we should know the details error. Then in order to get the details error,  please try to enable the wcf tracing as following:

    Right click on webconfig->open Edit WCF config manager-> Click on Diagnostics-Right hand pane click on Enable Tracing

    Note down or specify where the .svclog file should be generated.

    Now run the application and let it error out. Then close the application and recover the .svclog file.

    Open the same in svctraceviewer or attach the details or the file so that we can exactly pin point what exactly is going wrong.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 4, 2014 7:15 AM
    Moderator
  • Hi,

    Thanks for your reply. My application is self hosted service. how can i enable wcf tracing? Is there any other way for wcf tracing?


    sujithsb

    Tuesday, March 4, 2014 12:39 PM
  • Actually my requirement is to handle


    sujithsb

    Wednesday, March 5, 2014 4:20 AM
  • Hi,

    Please check my reply in your provious thread:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/d8ebc87d-b1a5-41b0-bdfc-bea8b59f0943/http-get-request-handling-with-empty-absolute-url?forum=wcf .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 11, 2014 7:54 AM
    Moderator
  • HI,

    This is another issue. To Handle Asynchronous requests using WCF.


    sujithsb

    Tuesday, March 11, 2014 12:56 PM