i have a web method that reads a file as MemoryStream, but while testing my service i get this error:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Timeouts are not supported on this stream.
at System.IO.Stream.get_ReadTimeout()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write4_MemoryStream(String n, String ns, MemoryStream o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write6_MemoryStream(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.MemoryStreamSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
no idea for what happening and confused as i know that there is no TimeOut limit for MemoryStreams. any help is appreciated.
this is my web method:
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public MemoryStream getApp()
{
string aid = "0";
if (Context.Request.QueryString["aid"] != null) aid=Context.Request.QueryString["aid"];
MemoryStream memSTR = new MemoryStream();
memSTR = CommonClasses.getAppStream(aid);
return memSTR;
}
and i call my service with this url: http://localhost:3430/idx.asmx/getApp?aid=2018
and this is CommonClasses.getAppStream(aid):
public static MemoryStream getAppStream(string tID)
{
string connectionString = ConfigurationManager.ConnectionStrings["DBCnn"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
int tID = int.Parse(tID);
connection.Open();
SqlCommand command = new SqlCommand("SPGetApp", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@AID", SqlDbType.Int).Value = tID;
SqlDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.CloseConnection);
MemoryStream memoryStream = new MemoryStream();
if (reader.Read())
{
var blob = new Byte[(reader.GetBytes(0, 0, null, 0, int.MaxValue))];
reader.GetBytes(0, 0, blob, 0, blob.Length);
memoryStream.Write(blob, 0, blob.Length);
}
reader.Close();
connection.Close();
return memoryStream;
}
if you think it's may some miss configuration in web.config causes the problem, this is my configuration file content:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<webServices>
<protocols>
<add name="HttpGet"/>
</protocols>
</webServices>
<pages controlRenderingCompatibilityVersion="4.0"/>
</system.web>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="DBCnn" connectionString="Data Source=.;Initial Catalog=myDatabase;Persist Security Info=True;User ID=myUserID;Password=myPassword; Connection Lifetime=0;Min Pool Size=10;Max Pool Size=300; Pooling=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>