我有源代码:
string epcisSettings = ConfigurationManager.AppSettings["EPCISSettings"];
if (!epcisSettings.EndsWith(@"\"))
{
epcisSettings += @"\";
}
string filePath = epcisSettings + ((BizStepCode)bizStepItems.BizStepCode).ToString().ToUpper() + ".xml";
File.WriteAllText(filePath, "");
LogWriter.LogOutput(LogType.INFO, "DAOEpcRecords.addEpcRecords", "EPCISSettingsFilePath = " + filePath);
LocationMasterRecords locationMasterRecords = new DAOLocationMasterRecords(this.connectionString).getLocationMasterRecords();
LocationMasterRecords.LocationMasterItems locationMasterItems = locationMasterRecords.LocationMasterList.Where(q => q.LocationCode == bizStepItems.LocationCode).First();
using (StreamReader reader = new StreamReader(filePath))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ObjectEventType));
ObjectEventType objectEventType = new ObjectEventType();
objectEventType = (ObjectEventType)xmlSerializer.Deserialize(reader);
objectEventType.epcList = epcList.ToArray();
objectEventType.eventTime = DateTime.Now;
objectEventType.eventTimeZoneOffset = DateTime.Now.ToString("zzz");
ReadPointType readPointType = new ReadPointType();
readPointType.id = "1";
objectEventType.readPoint = readPointType;
BusinessLocationType businessLocationType = new BusinessLocationType();
businessLocationType.id = "12";
objectEventType.bizLocation = businessLocationType;
EPCISDocumentType epcisDoc = new EPCISDocumentType();
epcisDoc.EPCISBody = new EPCISBodyType();
epcisDoc.EPCISBody.EventList = new object[1];
epcisDoc.EPCISBody.EventList[0] = objectEventType;
byte[] bsRequest = EpcSerializer.ToEPCISDocumentTypeBytes(epcisDoc);
HttpCli client = new HttpCli();
client.Open(Properties.Settings.Default.CoreCaptureServiceURI);
client.DoPost(bsRequest, "text/xml; charset=utf-8", null, 60000);
if (client.StatusCode != HttpStatusCode.OK)
{
throw new Exception("HTTP " + client.StatusCode + " ");
}
}
这是类错误:objectEventType = (ObjectEventType)xmlSerializer.Deserialize(reader);
XML文档(0,0)中存在错误。我在很多方面尝试过,但它没有运行。下面是我的xml文件,我在许多不同的论坛上找到了答案,但是当放入代码时它不起作用。
<epcis:EPCISDocument xmlns:epcis="urn:epcglobal:epcis:xsd:1" xmlns:cbvmda="urn:epcglobal:cbv:mda">
<EPCISBody>
<EventList>
<ObjectEventType>
<eventTime>2018-04-10T15:00:02.449Z</eventTime>
<eventTimeZoneOffset>+09:00</eventTimeZoneOffset>
<epcList>
<epc>urn:epc:id:giai:1234567.1111</epc>
<epc>urn:epc:id:giai:1234567.222</epc>
<epc>urn:epc:id:giai:1234567.33</epc>
</epcList>
<bizStep>urn:epcglobal:cbv:bizstep:commissioning</bizStep>
<disposition>urn:epcglobal:cbv:disp:active</disposition>
<readPoint>
<id>urn:epc:id:sgln:0400001.00300.0</id>
</readPoint>
<bizLocation>
<id>urn:epc:id:sgln:04000001.00300.0</id>
</bizLocation>
<extension>
<ilmd>
<cbvmda:itemExpirationDate>2015-03-15</example:expiry>
<cbvmda:lot>A123</example:lot>
</ilmd>
</extension>
</ObjectEventType>
</EventList>
</EPCISBody>
</epcis:EPCISDocument>