title: How to send byte array in jmeter post request
body: <p>There is a WCF service. The method i have to access has 1 parameter as input whoes type is Stream.</p>
  
  <p>I don't know how to provide stream object from JMeter to the WCF service.</p>
  
  <p>Currently i have written a C# method (MVC Project) which accepts string from JMeter and then converts it into Stream type object, Which is than processed by the WCF service. But this approach does not give does not give the actual performance of the WCF service</p>
  
  <pre><code>[WebInvoke(UriTemplate = "", Method = "POST")]
      [OperationContract]
      public Stream ReceiveChirp(Stream fileContents)
      {
          string response = "";
          long ticks = DateTime.Now.Ticks;
          DateTime receiveTime = DateTime.Now;
  </code></pre>
  
  <p>Currently i am getting an exception of object type.</p>
  
  <p>Here is the exception :</p>
  
  <pre><code>       &lt;p class="heading1"&gt;Request Error&lt;/p&gt;
      &lt;p xmlns=""&gt;The server encountered an error processing the request. Please see the &lt;a rel="help-page" href="http://t2vnmeterservicessciexp.cloudapp.net/ReceiveChirp/help"&gt;service help page&lt;/a&gt; for constructing valid requests to the service. The exception message is 'Object reference not set to an instance of an object.'. See server logs for more details. The exception stack trace is: &lt;/p&gt;
        &lt;p&gt;   at Base.VN.Core.Generic.GenericExtensions.ChirpGenerator.ConvertStringToByteArray(String input)
     at T2.VN.Core.MeterServices.MainEndPoint.ReceiveChirp(Stream fileContents)
     at SyncInvokeReceiveChirp(Object , Object[] , Object[] )
     at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp;amp; outputs)
     at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)&lt;/p&gt;
  </code></pre>
  
  <p><strong>The code my colleague is using to unit test the same:</strong></p>
  
  <pre><code>public string TestServicePacket(string data)
          {
              var url = "http://test.net/";
              var requestUrl = string.Format("{0}/ReceiveChirp/", url);
              var request = (HttpWebRequest)WebRequest.Create(requestUrl);
              request.Timeout = Timeout.Infinite;
              request.Method = "POST";
              request.ContentType = "text/plain";
  
              var dataTrailing = "&amp;UserName=eReg&amp;UserPassword=abc123";
              var dataTrailingBytes = Encoding.ASCII.GetBytes(dataTrailing);
  
              var bChirp = ConvertStringToByteArray(data);
  
              var ToSend = new byte[dataTrailingBytes.Length + bChirp.Length];
              ToSend = bChirp.Concat(dataTrailingBytes).ToArray();
  
              request.ContentLength = ToSend.Length;
  
              using (var requestStream = request.GetRequestStream())
              {
                  // Send the file as body request.
                  requestStream.Write(ToSend, 0, ToSend.Length);
                  requestStream.Close();
              }
              var response = (HttpWebResponse)request.GetResponse();
              var responseStream = response.GetResponseStream();
              var memoryStream = new MemoryStream();
              string resultResponse;
  
              resultResponse = ConvertStream(responseStream);
              return resultResponse;
          }
  </code></pre>