POST
|
... and the handler itself:
private byte[] PngHandler(System.Collections.Specialized.NameValueCollection boundVariables,
ESRI.ArcGIS.SOESupport.JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
responseProperties = "{\"Content-Type\" : \"image/png\"}";
System.IO.FileStream fs = new System.IO.FileStream("c:\\temp\\8540.png", System.IO.FileMode.Open);
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
const int count = 1024;
while(true)
{
byte[] buf = br.ReadBytes(count);
ms.Write(buf, 0, buf.Length);
if (buf.Length < count)
break;
}
br.Close();
fs.Close();
fs.Dispose();
return ms.ToArray();
}
That was a real good template, but can be simplified and generalized in several ways: For reading a file in .net you can simply use File.ReadAllBytes(path); Determining the correct mime type is discussed here Setting the responseProperties is much easier when using the JsonObject This results in two little functions, which do the job:
protected string GetMimeType(FileInfo fileInfo)
{
string mimeType = "application/unknown";
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(fileInfo.Extension.ToLower());
if (regKey != null)
{
object contentType = regKey.GetValue("Content Type");
if (contentType != null)
mimeType = contentType.ToString();
}
return mimeType;
}
protected byte[] FileHandler(string path, out string responseProperties)
{
FileInfo f = new FileInfo(path);
string contentType = GetMimeType(f);
long contentLength = f.Length;
JsonObject props = new JsonObject();
props.AddString("Content-Type", contentType);
props.AddLong("Content-Length", contentLength);
props.AddString("Pragma", "public");
props.AddString("Cache-control", "must-revalidate");
props.AddString("Content-Disposition", "inline; filename=\"" + path + "\"");
responseProperties = props.ToJson();
return File.ReadAllBytes(path);
}
... View more
08-18-2011
03:34 AM
|
1
|
0
|
209
|
POST
|
Building a new RecordSet with a field of esriFieldType.esriFieldTypeOID and Editable = true is not editable at all! This fieldtype implies obviously, that the field can't be edited. If you use esriFieldType.esriFieldTypeInteger instead, it works fine. Example: // define new recordset with cols id and txt IRecordSet rs = new RecordSet(); IRecordSetInit rsDefinition = rs as IRecordSetInit; IFields rsFields = new Fields(); IFieldsEdit rsFieldsEdit = rsFields as IFieldsEdit; rsFieldsEdit.FieldCount_2 = 2; IField rsField = new ESRI.ArcGIS.Geodatabase.Field(); IFieldEdit rsFieldEdit = rsField as IFieldEdit; rsFieldEdit.Name_2 = "id"; //rsFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; <<< is not editable!!! rsFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; //<<< use Integer instead rsFieldEdit.Editable_2 = true; // doesn't make esriFieldTypeOID editable!!! rsFieldsEdit.set_Field(i, rsField); rsField = new ESRI.ArcGIS.Geodatabase.Field(); rsFieldEdit = rsField as IFieldEdit; rsFieldEdit.Name_2 = "txt"; rsFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; rsFieldEdit.Length_2 = 80; rsFieldEdit.Editable_2 = true; rsFieldsEdit.set_Field(i, rsField); rsDefinition.CreateTable(rsFields); ICursor rsCursor = rsDefinition.Insert(); IRowBuffer rowBuffer = rsDefinition.CreateRowBuffer(); rowBuffer.set_Value(0, 1); // throws execption if esriFieldTypeOID is used!!! rowBuffer.set_Value(1, "blabla"); Bug or feature? Even if the created Recordset never will be stored in a DB, you can't use e.g. field definitions from an existing table, but have to replace esriFieldTypeOID with esriFieldTypeInteger. (AGS 10 SDK)
... View more
08-09-2011
07:40 AM
|
0
|
1
|
963
|
Title | Kudos | Posted |
---|---|---|
1 | 08-18-2011 03:34 AM |
Online Status |
Offline
|
Date Last Visited |
09-28-2023
07:20 AM
|