System information

Table Of Contents
i.LON SmartServer 2.0 Programmer’s Reference
20-24
// create the response object
Item_Coll itemColl_resp = new Item_Coll();
itemColl_resp.Item = new Item[] { new Item() };
itemColl_resp.Item[0].UCPTname = iLonItem.Item[0].UCPTname;
// is the Item of the expected type?
if (!(iLonItem.Item[0] is Dp_Data)) {
System.Diagnostics.Trace.WriteLine("ERROR, unexpected object type");
++itemColl_resp.UCPTfaultCount;
itemColl_resp.UCPTfaultCountSpecified = true;
itemColl_resp.Item[0].fault = new E_Fault();
itemColl_resp.Item[0].fault.faultcode = new
E_FaultFaultcode();
itemColl_resp.Item[0].fault.faultcode.faultType = Fault_eType._error;
itemColl_resp.Item[0].fault.faultcode.Value = 12; /* eFECommandFailed */
itemColl_resp.Item[0].fault.faultstring = "Unexpected object type";
}
// everything is fine, proceed..
else {
Dp_Data dpData = (Dp_Data)iLonItem.Item[0];
System.Diagnostics.Trace.WriteLine(String.Format("The value is: '{0}'",
dpData.UCPTvalue[0].Value));
// Handle the attachment file
SoapContext soapContext = RequestSoapContext.Current;
if (soapContext != null) {
// If there is an attachment file
if (soapContext
.Attachments.Count > 0) {
System.Diagnostics.Trace.WriteLine("attachment-id: " +
soapContext.Attachments[0].Id);
if (soapContext.Attachments[0].ContentType == "text/plain"
|| soapContext.Attachments[0].ContentType == "text/xml")
{
string attachment;
System.IO.StreamReader attachmentStream
= new System.IO.StreamReader(soapContext.Attachments[0].Stream);
// Read the attachment file to the end
attachment = attachmentStream.ReadToEnd();
attachmentStream.Close();
// Write the contents of the file
System.Diagnostics.Trace.WriteLine(attachment);
}
}
}
}
return itemColl_resp;
}
/// <remarks/>
public void Clear(ref Item_Coll iLonItem) {
}
/// <remarks/>
public void InvokeCmd(ref Item_Coll iLonItem) {
}
}
}
8. Before you run the application, you need to change web.config file as follows. You can open
web.config file from the Solution Explorer. Add the following snippet at the top of the
<configuration> element.
<?xml version="1.0"?>
<configuration>
<configSections>