100 Character Limit on Accepting Payload of HTTP POST in my WCF Service?
Hello,
I have a WCF Service that takes the payload of an HTTP
POST and saves it as a string. However, it only seems to work when the
payload is 99 characters or less. For example, I can make the payload
99 a's and it works. But, if I add on one more 'a', suddenly there is
no response! This strange behavior works quite consistently.
Is there some reason for this, and more
importantly, how can I make my program work for the huge payloads I am
aiming for? I have included below my entire .cs file (there is no app
config file)
Any help would be greatly appreciated! Thanks!
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Web;
using System.Text;
using System.Web;
using System.Xml;
public class getString
{
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke]
void SaveString(Stream stream);
}
public class Service : IService
{
public void SaveString(Stream text)
{
/* stringText is POST payload stream converted to type string */
string stringText = new StreamReader(text).ReadToEnd().Replace('*','\n');
string currentTime = DateTime.Now.ToString();
Console.WriteLine("\n{0}: Request received", currentTime);
string currentTimeFormatted = DateTime.Now.ToString().Replace('/', '-').Replace(' ','_').Replace(':', '_');
string currentFileName = "POSTPayload_" + currentTimeFormatted + ".xml";
string currentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string desiredXmlFolder = "XMLResults";
StreamWriter streamWriter = new StreamWriter(desiredXmlFolder + "\\" + currentFileName);
streamWriter.WriteLine(stringText);
streamWriter.Close();
int currentFileSize = stringText.Length + 2;
Console.WriteLine("HTTP POST payload saved as file:\nName: {0}\nDirectory: {1}\nExpected File Size: {2} bytes\n\n\nService running...\nPress <ENTER> To Exit\n\n", currentFileName, (currentDirectory + "\\" + desiredXmlFolder), currentFileSize);
}
}
static Binding GetBinding()
{
BasicHttpBinding result = new BasicHttpBinding();
return result;
}
public static void Main()
{
string baseAddress = "http://10.2.2.61:8004/Service";
WebServiceHost host = new WebServiceHost(typeof(Service), new Uri(baseAddress));
host.Open();
Console.WriteLine("HTTP POST Payload Receiver\nWCF Web Service\n\nDefault Web Host: {0}\n", baseAddress);
Console.WriteLine("1 - Modify Web Host\n2 - Exit\nPress <ENTER> To Run\n");
string userChoice = Console.ReadLine();
if (userChoice == "1")
{
Console.WriteLine("\nUSEAGE: http://<IPv4>:<Port>/<Directory>");
Console.Write("\nIPv4: ");
string ipv4 = Console.ReadLine();
Console.Write("Port: ");
string port = Console.ReadLine();
Console.Write("Directory: ");
string directory = Console.ReadLine();
baseAddress = "http://" + ipv4 + ":" + port + "//" + directory;
Console.Write("\n");
}
else if (userChoice == "2")
Environment.Exit(1);
else { }
Console.WriteLine("Web Host: {0}\n", baseAddress);
WebClient client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "text/plain";
Console.WriteLine("Service running...\nPress <ENTER> To Exit\n");
Console.ReadLine();
host.Close();
}