I have a WCF web service with basicHTTPBinding, on the server side the transmission mode is streamedRequest, because the client will send us a large file as a memory stream.
But on the client side, when I use the transfer mode as streamedRequest, it gives me this error
"The remote server returned an error: (400) Bad request
And when I look at the information, I see this as an error message Exception: there is a problem with the XML received from the network For more information, see Internal Exception.
InnerException: The message body cannot be read because it is empty.
I can send up to 5 MB of data using trasfermode as buffered, but this will affect the performance of my web service in the long run if there are many clients trying to access the service in buffered mode.
SmartConnect.Service1Client Serv = new SmartConnectClient.SmartConnect.Service1Client();
SmartConnect.OrderCertMailResponse OrderCert = new SmartConnectClient.SmartConnect.OrderCertMailResponse();
OrderCert.UserID = "abcd";
OrderCert.Password = "7a80f6623";
OrderCert.SoftwareKey = "90af1";
string applicationDirectory = @"\\inid\utty\Bran";
byte[] CertMail = File.ReadAllBytes(applicationDirectory + @"\5mb_test.zip");
MemoryStream str = new MemoryStream(CertMail);
OrderCert.File = str;
MemoryStream FileStr = str;
Serv.OrderCertMail(OrderCert);
lblON.Text = OrderCert.OrderNumber;
Serv.Close();
[OperationContract]
OrderCertMailResponse OrderCertMail(OrderCertMailResponse OrderCertMail);
[MessageContract]
public class OrderCertMailResponse
{
string userID = "";
string password = "";
string softwareID = "";
MemoryStream file = null;
[MessageHeader]
public string UserID
{
get { return userID; }
set { userID = value; }
}
[MessageHeader]
public string Password
{
get { return password; }
set { password = value; }
}
[MessageHeader]
public string SoftwareKey
{
get { return softwareID; }
set { softwareID = value; }
}
[MessageBodyMember]
public MemoryStream File
{
get { return file; }
set { file = value; }
}
[MessageHeader]
public string ReturnMessage;
[MessageHeader]
public int ReturnCode;
[MessageHeader]
public string OrderNumber;
}
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class Service1 : IService1
{
public OrderCertMailResponse OrderCertMail(OrderCertMailResponse OrderCertMail)
{
OrderService CertOrder = new OrderService();
ClientUserInfo Info = new ClientUserInfo();
ControlFileInfo Control = new ControlFileInfo();
Info.UserName = OrderCertMail.UserID.ToString();
Info.Password = OrderCertMail.Password.ToString();
Info.SoftwareKey = OrderCertMail.SoftwareKey.ToString();
OrderCertMailResponseClass OrderCertResponse = CertOrder.OrderCertmail(Info,Control,OrderCertMail.File);
OrderCertMail.ReturnMessage = OrderCertResponse.ReturnMessage.ToString();
OrderCertMail.ReturnCode = Convert.ToInt32(OrderCertResponse.ReturnCode.ToString());
OrderCertMail.OrderNumber = OrderCertResponse.OrderNumber;
return OrderCertMail;
}
Below is my new contract for an operation that only accepts a data stream as a parameter
[OperationContract]
SmartStream SendStream(MemoryStream DataStream);
public SmartStream SendStream(MemoryStream DataStream)
{
OrderService CertOrder = new OrderService();
ClientUserInfo Info = new ClientUserInfo();
ControlFileInfo Control = new ControlFileInfo();
MemoryStream serverStream = null;
Info.Password = "78f24dsfsdf96623";
Info.SoftwareKey = "dfs6dbb71";
Info.UserName = "ssfsdf";
using (serverStream = new MemoryStream(100))
{
int count = 0;
const int buffLen = 4096;
byte[] buf = new byte[buffLen];
while ((count = CertFile.Read(buf, 0, buffLen)) > 0)
{
serverStream.Write(buf, 0, count);
}
CertFile.Close();
serverStream.Close();
return null;
}
My client method for accessing
protected void Page_Load(object sender, EventArgs e)
{
SmartConnect.Service1Client Serv = new
SmartConnectClient.SmartConnect.Service1Client();
string applicationDirectory = @"\\intrepid\utility\Bryan";
byte[] CertMail = File.ReadAllBytes(applicationDirectory + @"\100mb_test.zip");
MemoryStream str = new MemoryStream(CertMail);
SmartConnectClient.SmartConnect.SendStreamRequest request =
new SmartConnectClient.SmartConnect.SendStreamRequest();
SmartConnectClient.SmartConnect.SmartStream SmartStr =
new SmartConnectClient.SmartConnect.SmartStream();
request.DataStream = str;
SmartConnectClient.SmartConnect.SendStreamResponse response = Serv.SendStream(request);
}