fireside
(FireSide Experience)
April 5, 2019, 11:51am
1
Hi,
I have an image field stored in my SQL DB. In my R.O. Server I get data via the DA server and populate a custom Struct to send to my client. The type I use in the struct is Binary however the data I am getting from DA of the image is byte[]. How do I get convert that to the Binary type so my c# client can display the image? Can I send the image to my client any other way?
Thanks!
antonk
(antonk)
April 5, 2019, 3:11pm
3
Hello
The Binary
data type provides several constructors. One of them accepts byte[]
array an an initial value, so all you need to do is just to create a Binary
instance using code like
var byteArray = ...field value retrieved from DB...
var image = new Binary(byteArray);
Regards
fireside
(FireSide Experience)
April 5, 2019, 6:11pm
4
wow, that was a simple solution… thanks!
However, I am getting this error when running the server now. I think I am still missing something. This is the method I wrote to handle the image byte[]
private Binary ByteToBinary(byte[] byteArray)
{
var b = new Binary(byteArray);
return b;
}
Everything compiles fine just get the error when running the server.
This is the CreateCard method
private CardData GetCardData(Cards card)
{
var cd = new CardData();
cd.CardID = card.CardID;
cd.AbilityID = card.AbilityID;
cd.BackStory = card.BackStory;
cd.Class = card.Class;
cd.Endurance = card.Endurance;
cd.Energy = card.Energy;
cd.Influence = card.Influence;
cd.Instrument = card.Instrument;
cd.Name = card.Name;
cd.Number = card.Number;
cd.Quality = card.Quality;
cd.Type = card.Type;
cd.SubType = card.SubType;
cd.Archived = card.Archived;
cd.Image = ByteToBinary(card.Image);
cd.Owned = false;
return cd;
}
antonk
(antonk)
April 5, 2019, 6:16pm
5
Seems you copy-pasted a wrong part of code. Could you show the definition of the CreateCard
method?
fireside
(FireSide Experience)
April 5, 2019, 6:17pm
6
ah, you mean this?
namespace Fireside.WOS.Server
{
public class CardData: RemObjects.SDK.Types.ComplexType
{
public Int32 CardID { get; set; }
public Int32 Number { get; set; }
public string Name { get; set; }
public string Class { get; set; }
public string Type { get; set; }
public string SubType { get; set; }
public string Ability { get; set; }
public Int32 AbilityID { get; set; }
public string Instrument { get; set; }
public string Quality { get; set; }
public Int32 Energy { get; set; }
public Int32 Endurance { get; set; }
public Int32 Influence { get; set; }
public bool Archived { get; set; }
public string BackStory { get; set; }
public bool Owned { get; set; }
public Binary Image { get; set; }
}
}
fireside
(FireSide Experience)
April 5, 2019, 6:19pm
7
this…
[ServiceMethod]
public CardData CreateCard(CardData newcard)
{
var c = new Cards();
c.AbilityID = newcard.AbilityID;
c.BackStory = newcard.BackStory;
c.Class = newcard.Class;
c.Endurance = newcard.Endurance;
c.Energy = newcard.Energy;
c.Influence = newcard.Influence;
c.Instrument = newcard.Instrument;
c.Name = newcard.Name;
c.Number = newcard.Number;
c.Quality = newcard.Quality;
c.Type = newcard.Type;
#hint need to handle image
c.Image = newcard.Image.ToArray();
WOS.Server.DataAccess.sharedInstance.rda.InsertRow(c);
WOS.Server.DataAccess.sharedInstance.rda.ApplyChanges();
// return a valid card after looking it up in the Database
var nc = (from cs in WOS.Server.DataAccess.sharedInstance.rda.GetTable<Cards>()
where cs.Name == newcard.Name
select cs).FirstOrDefault();
return GetCardData(nc);
}
fireside
(FireSide Experience)
April 5, 2019, 6:26pm
9
humm, I am really don’t understand why this error… I commented out the image assignment code and still get the error. That part was working before.
antonk
(antonk)
April 5, 2019, 6:27pm
10
Could you also send to support@ the “ServerRodl.rodl” file. It should have been auto-created next to your server’s .exe file. This is a diagnostics file that is created only if a CodeFirst server fails to start due to RODL generation issues and a debugger is already attached to this server instance (i.e. it is not created in production code)
fireside
(FireSide Experience)
April 5, 2019, 6:30pm
11
I usually do see the rodl file but not in this case… strange
Can I manually produce it somehow?
antonk
(antonk)
April 5, 2019, 6:43pm
12
Could you send me (to support@ ) the entire folder with compiled server? Or at least the CardService.cs file (you can delete method bodies, all I need to see is the methods/parameters)?
antonk
(antonk)
April 5, 2019, 6:59pm
14
Thanks for the code, but the error doesn’t reproduce on it.
Please try to delete the folder containing your compiled server app and to fully rebuild it again.
fireside
(FireSide Experience)
April 5, 2019, 7:05pm
15
Thanks antonk for looking into this. I will try what you suggested and look into it further.
fireside
(FireSide Experience)
April 5, 2019, 7:07pm
16
Ok, I backed out all my changes and got a good build that worked… than I changed just this one thing and got the error…
namespace Fireside.WOS.Server
{
public class CardData: RemObjects.SDK.Types.ComplexType
{
public Int32 CardID { get; set; }
public Int32 Number { get; set; }
public string Name { get; set; }
public string Class { get; set; }
public string Type { get; set; }
public string SubType { get; set; }
public string Ability { get; set; }
public Int32 AbilityID { get; set; }
public string Instrument { get; set; }
public string Quality { get; set; }
public Int32 Energy { get; set; }
public Int32 Endurance { get; set; }
public Int32 Influence { get; set; }
public bool Archived { get; set; }
public string BackStory { get; set; }
public bool Owned { get; set; }
public Binary image { get; set; } // <--- Made change here!!!!
}
}
And got the same error. It seems to not like the Binary type. Is that the correct type I should be using?
Thanks!
fireside
(FireSide Experience)
April 5, 2019, 7:27pm
17
Found a solution… apparently I need to define the type explicitly like this
public RemObjects.SDK.Types.Binary Image { get; set; }
This works!
antonk
(antonk)
April 6, 2019, 8:42am
18
Ah. That was a naming conflict. It seems that the compiler resolved this line
public Binary image ...
to a wrong Binary
type (not the one defined in Remoting SDK, so it was obviously not supported by Remoting SDK). Once you changed code to
public RemObjects.SDK.Types.Binary Image ...
the compiler was able to properly determine which exactly type it should be using.