It cannot return list of T , it cannot return memorystream, cannot return anything.
So how would i build that?
If i do:
When i try to use the service from an app like this:
Will error: Cannot convert type 'DXWebApplication2.RootObject' to 'DXWebApplication2.ServiceReferenceData.RootObject'
Also something like this on the WCF:
will not accept the memorystream,.
So how can i do this to work?
Thanks.
So how would i build that?
If i do:
Code:
// Iservice
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
string JsonSerialize(RootObject root);
//Service
public string JsonSerialize(RootObject root) {
string sserialized = new JavaScriptSerializer().Serialize(root);
return sserialized;
}
Code:
var objectToSerialize = new RootObject();
objectToSerialize.maindataclass = new List<MainDataClass>
{
new MainDataClass {
AllowDBNull = true,
Caption = "p",
ColumnName = "myc",
MaxLength = 40,
Readonly = false
},
new MainDataClass {
AllowDBNull = true,
Caption = "p2",
ColumnName = "myc2",
MaxLength = 40,
Readonly = false
}
};
string jsonString = new JavaScriptSerializer().Serialize(objectToSerialize);
IwcfdataClient srv = new ServiceReferenceData.IwcfdataClient();
// the error is below!
string jsonstring = srv.JsonSerialize((ServiceReferenceData.RootObject)objectToSerialize);
Also something like this on the WCF:
Code:
public T DeserializeJSon<T>(string jsonString)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T obj = (T)ser.ReadObject(stream);
return obj;
}
So how can i do this to work?
Thanks.