I'm facing a problem with a WCF Restfull Webservice, the problem is with one method the others are working correctly, then I think it isn't a general configuration problem. I have an idea of what could be the problem but actually I don't know how to solve it. The method have access to a third party webservice to retrieve an object of the following class:
我遇到了WCF Restfull Webservice的问题,问题在于其他方法正常工作的一种方法,那么我认为这不是一般的配置问题。我知道可能是什么问题,但实际上我不知道如何解决它。该方法可以访问第三方Web服务以检索以下类的对象:
[DataContract]
public class DeviceData
{
[DataMember]
public int DeviceDataFull { get; set; }
[DataMember]
public string DeviceDataVersion { get; set; }
[DataMember]
public string DeviceDataModel { get; set; }
[DataMember]
public int DeviceDataZWave_Heal { get; set; }
[DataMember]
public string DeviceDataTemperature { get; set; }
[DataMember]
public string DeviceDataSkin { get; set; }
[DataMember]
public string DeviceDataSerial_Number { get; set; }
[DataMember]
public string DeviceDataFWD1 { get; set; }
[DataMember]
public string DeviceDataFWD1Token { get; set; }
[DataMember]
public string DeviceDataFWD2 { get; set; }
[DataMember]
public string DeviceDataFWD2Token { get; set; }
[DataMember]
public int DeviceDataMode { get; set; }
[DataMember]
public List<Section> DeviceDataSections { get; set; }
[DataMember]
public List<Room> DeviceDataRooms { get; set; }
[DataMember]
public List<Scene> DeviceDataScenes { get; set; }
[DataMember]
public List<DeviceItem> DeviceDataItems { get; set; }
[DataMember]
public List<Category> DeviceDataCategories { get; set; }
[DataMember]
public int DeviceDataIr { get; set; }
[DataMember]
public string DeviceDataIrtx { get; set; }
[DataMember]
public int DeviceDataLoadTime { get; set; }
[DataMember]
public int DeviceDataState { get; set; }
[DataMember]
public string DeviceDataComment { get; set; }
}
The only thing that I did in the method's code is fill this object, well in the piece of code where I'm trying to get the: public List<DeviceItem> DeviceDataItems { get; set; }
is the problem because I test the method without it and work perfectly. this list of DeviceItem have objects of inherit classes of Device Item:
我在方法代码中唯一做的就是填充这个对象,以及我正在尝试获取的代码片段:public List
DeviceItemPanel : DeviceItem
DeviceItemPanelPartition : DeviceItem
DeviceItemDimmable : DeviceItem
DeviceItemThermostat : DeviceItem
etc..
My question: Is there any restriction in service architecture to return the class of object that I explaining above? Because when I execute the method it remain load and after a few seconds I get the message: ERR_CONNECTION_RESET, I don't see any other error code or anything else, I also debug the method and everything work fine the problem is when it try to return the object as a JSON format. If any one could help me to find a solution I will appreciate it a lot. Note this the code of the webservice method:
我的问题:服务架构是否有任何限制来返回我在上面解释的对象类?因为当我执行方法时它仍然加载,几秒钟后我收到消息:ERR_CONNECTION_RESET,我没有看到任何其他错误代码或其他任何东西,我也调试方法,一切正常,问题是当它试图将对象作为JSON格式返回。如果有人能帮助我找到解决方案,我会非常感激。请注意webservice方法的代码:
public ResultDeviceData GetDeviceData(string User, string Password, string DeviceNumber)
{
ResultDeviceData result = new ResultDeviceData();
try
{
Identity identity = GetUserIdentityPrivate(User, Password);
DeviceInfo info = GetDeviceInfoByNumber(User, Password, DeviceNumber);
string url = "https://" + info.DeviceInfoServerRelay + "/relay/relay/relay/device/" + info.DeviceNumber + "/port_3480/data_request?id=lu_sdata&output_format=json";
string jsonResult = Request_Get(url, null, null, info.DeviceInfoServerRelayToken);
//Read Json
var obj = JObject.Parse(jsonResult);
DeviceData data = new DeviceData();
data.DeviceDataFull = (int)obj.SelectToken("full");
data.DeviceDataVersion = (string)obj.SelectToken("version");
data.DeviceDataModel = (string)obj.SelectToken("model");
data.DeviceDataZWave_Heal = (int)obj.SelectToken("zwave_heal");
data.DeviceDataTemperature = (string)obj.SelectToken("temperature");
data.DeviceDataSkin = (string)obj.SelectToken("skin");
data.DeviceDataSerial_Number = (string)obj.SelectToken("serial_number");
data.DeviceDataFWD1 = (string)obj.SelectToken("fwd1");
data.DeviceDataFWD1Token = Request_Get("https://" + data.DeviceDataFWD1 + "/info/session/token", identity.IdentityFirm, identity.IdentitySignature, null);
data.DeviceDataFWD2 = (string)obj.SelectToken("fwd2");
data.DeviceDataFWD2Token = Request_Get("https://" + data.DeviceDataFWD2 + "/info/session/token", identity.IdentityFirm, identity.IdentitySignature, null);
data.DeviceDataMode = (int)obj.SelectToken("mode");
data.DeviceDataIr = (int)obj.SelectToken("ir");
data.DeviceDataIrtx = (string)obj.SelectToken("irtx");
data.DeviceDataLoadTime = (int)obj.SelectToken("loadtime");
data.DeviceDataState = (int)obj.SelectToken("state");
data.DeviceDataComment = (string)obj.SelectToken("comment");
data.DeviceDataSections = new List<Section>();
data.DeviceDataRooms = new List<Room>();
data.DeviceDataScenes = new List<Scene>();
data.DeviceDataCategories = new List<Category>();
data.DeviceDataItems = new List<DeviceItem>();
//Loading Sections
var sections = JArray.Parse(obj.SelectToken("sections").ToString());
for (int i = 0; i < sections.Count; i++)
{
Section section = new Section();
section.SectionId = (int)sections[i].SelectToken("id");
section.SectionName = (string)sections[i].SelectToken("name");
data.DeviceDataSections.Add(section);
}
//Loading Rooms
var rooms = JArray.Parse(obj.SelectToken("rooms").ToString());
for (int i = 0; i < rooms.Count; i++)
{
Room room = new Room();
room.RoomId = (int)rooms[i].SelectToken("id");
room.RoomName = (string)rooms[i].SelectToken("name");
room.SectionId = (int)rooms[i].SelectToken("section");
data.DeviceDataRooms.Add(room);
}
//Loading Scenes
var scenes = JArray.Parse(obj.SelectToken("scenes").ToString());
for (int i = 0; i < scenes.Count; i++)
{
Scene scene = new Scene();
scene.SceneId = (int)scenes[i].SelectToken("id");
scene.SceneName = (string)scenes[i].SelectToken("name");
scene.RoomId = (int)scenes[i].SelectToken("room");
scene.SceneActive = ((int)scenes[i].SelectToken("active")) != 0;
data.DeviceDataScenes.Add(scene);
}
//Loading Categories
var categories = JArray.Parse(obj.SelectToken("categories").ToString());
for (int i = 0; i < categories.Count; i++)
{
Category category = new Category();
category.CategoryId = (int)categories[i].SelectToken("id");
category.CategoryName = (string)categories[i].SelectToken("name");
data.DeviceDataCategories.Add(category);
}
//Loading Devices
var deviceItems = JArray.Parse(obj.SelectToken("devices").ToString());
for (int i = 0; i < deviceItems.Count; i++)
{
int DeviceItemId = (int)deviceItems[i].SelectToken("id");
string DeviceItemAltId = (string)deviceItems[i].SelectToken("altid");
string DeviceItemName = (string)deviceItems[i].SelectToken("name");
int RoomId = (int)deviceItems[i].SelectToken("room");
int CategoryId = (int)deviceItems[i].SelectToken("category");
int SubCategoryId = (int)deviceItems[i].SelectToken("subcategory");
int DeviceItemParent = (int)deviceItems[i].SelectToken("parent");
switch (CategoryId)
{
case 1:
{
break;
}
case 2:
{
DeviceItemDimmable dimmable = new DeviceItemDimmable();
dimmable.DeviceItemId = DeviceItemId;
dimmable.DeviceItemAltId = DeviceItemAltId;
dimmable.DeviceItemName = DeviceItemName;
dimmable.RoomId = RoomId;
dimmable.CategoryId = CategoryId;
dimmable.SubCategoryId = 0;
dimmable.DeviceItemParent = DeviceItemParent;
dimmable.DeviceItemDimmableStatus = (string)deviceItems[i].SelectToken("status");
dimmable.DeviceItemDimmableLevel = (string)deviceItems[i].SelectToken("level");
dimmable.DeviceItemDimmableState = (int)deviceItems[i].SelectToken("state");
dimmable.DeviceItemDimmableComment = (string)deviceItems[i].SelectToken("comment");
data.DeviceDataItems.Add(dimmable);
break;
}
case 3:
{
break;
}
case 4:
{
break;
}
case 5:
{
switch (SubCategoryId)
{
case 1:
{
DeviceItemThermostat thermostat = new DeviceItemThermostat();
thermostat.DeviceItemId = DeviceItemId;
thermostat.DeviceItemAltId = DeviceItemAltId;
thermostat.DeviceItemName = DeviceItemName;
thermostat.RoomId = RoomId;
thermostat.CategoryId = CategoryId;
thermostat.SubCategoryId = 0;
thermostat.DeviceItemParent = DeviceItemParent;
thermostat.DeviceItemThermostatFanMode = (string)deviceItems[i].SelectToken("fanmode");
thermostat.DeviceItemThermostatHvacState = (string)deviceItems[i].SelectToken("hvacstate");
thermostat.DeviceItemThermostatMode = (string)deviceItems[i].SelectToken("mode");
thermostat.DeviceItemThermostatSetPoint = (string)deviceItems[i].SelectToken("setpoint");
thermostat.DeviceItemThermostatHeat = (string)deviceItems[i].SelectToken("heat");
thermostat.DeviceItemThermostatCool = (string)deviceItems[i].SelectToken("cool");
thermostat.DeviceItemThermostatStatus = (string)deviceItems[i].SelectToken("status");
thermostat.DeviceItemThermostatBatteryLevel = (string)deviceItems[i].SelectToken("batterylevel");
thermostat.DeviceItemThermostatTemperature = (string)deviceItems[i].SelectToken("temperature");
thermostat.DeviceItemThermostatState = (int)deviceItems[i].SelectToken("state");
thermostat.DeviceItemThermostatComment = (string)deviceItems[i].SelectToken("comment");
data.DeviceDataItems.Add(thermostat);
break;
}
case 2:
{
break;
}
case 3:
{
break;
}
default:
break;
}
break;
}
case 6:
{
DeviceItemCamera camera = new DeviceItemCamera();
camera.DeviceItemId = DeviceItemId;
camera.DeviceItemAltId = DeviceItemAltId;
camera.DeviceItemName = DeviceItemName;
camera.RoomId = RoomId;
camera.CategoryId = CategoryId;
camera.SubCategoryId = 0;
camera.DeviceItemParent = DeviceItemParent;
camera.DeviceItemCameraIP = (string)deviceItems[i].SelectToken("ip");
camera.DeviceItemCameraURL = (string)deviceItems[i].SelectToken("url");
camera.DeviceItemCameraStreamming = (string)deviceItems[i].SelectToken("streaming");
camera.DeviceItemCameraVideoUrl = (string)deviceItems[i].SelectToken("videourls");
camera.DeviceItemCameraCommands = ((string)deviceItems[i].SelectToken("commands")).Split(',');
data.DeviceDataItems.Add(camera);
break;
}
case 22:
{
DeviceItemPanel panel = new DeviceItemPanel();
panel.DeviceItemId = DeviceItemId;
panel.DeviceItemAltId = DeviceItemAltId;
panel.DeviceItemName = DeviceItemName;
panel.RoomId = RoomId;
panel.CategoryId = CategoryId;
panel.SubCategoryId = 0;
panel.DeviceItemParent = DeviceItemParent;
data.DeviceDataItems.Add(panel);
break;
}
case 23:
{
DeviceItemPanelPartition panelPartition = new DeviceItemPanelPartition();
panelPartition.DeviceItemId = DeviceItemId;
panelPartition.DeviceItemAltId = DeviceItemAltId;
panelPartition.DeviceItemName = DeviceItemName;
panelPartition.RoomId = RoomId;
panelPartition.CategoryId = CategoryId;
panelPartition.SubCategoryId = 0;
panelPartition.DeviceItemParent = DeviceItemParent;
panelPartition.DeviceItemPanelPartitionAlarm = (string)deviceItems[i].SelectToken("alarm");
panelPartition.DeviceItemPanelPartitionAlarmMemory = (string)deviceItems[i].SelectToken("alarmmemory");
panelPartition.DeviceItemPanelPartitionArmMode = (string)deviceItems[i].SelectToken("armmode");
panelPartition.DeviceItemPanelPartitionDetailedArmMode = (string)deviceItems[i].SelectToken("detailedarmmode");
data.DeviceDataItems.Add(panelPartition);
break;
}
default:
{
}
break;
}
}
result.ResultMessage = "Data Retrieve";
result.ResultObject = data;
result.ResultValue = true;
}
catch (Exception e)
{
result.ResultMessage = e.Message;
result.ResultObject = null;
result.ResultValue = false;
}
return result;
}
1 个解决方案
#1
0
I solved the problem returning a string in the method, and Serializing the object inside the code.
我解决了在方法中返回字符串的问题,以及序列化代码中的对象。
return JsonConvert.SerializeObject(result);
#1
0
I solved the problem returning a string in the method, and Serializing the object inside the code.
我解决了在方法中返回字符串的问题,以及序列化代码中的对象。
return JsonConvert.SerializeObject(result);