Umbraco: /base method call should return an custom created object. But on my callback, I get an xmlDocument Object.
Hi,
I use /base call to call an web services. I dont have .asmx exposed with me. I have the wsdl file only. Hence I cannot use Jquery to call the .asmx method.
hence i go for /base in umbraco. I coded the web service call in my dll. and kept inside /bin of umbraco. And I configured the restExtensions to enable the method to access. Also I could access the method in the base, using javascript as follows.
Here "Hello" is the base method name, which takes 3 parameters (Sequence, optimization, motifs), which I could pass. But the return value "data" is an custom object which is returned by the base method. I need to read the "data" and get my values back in javascript. But I get an "object xmlDocument", when i alert "data". Can anyone tell me how to read the values in "data".??
And this is my base method:
public static mgxOptimizationResult Hello(string sequence, string codonusageId, string motifs ) { string[] motifs1 = new string[1];
motifs1[0] = motifs;
//webservice proxy object creation
GENEius.MGXServiceClient obj = new MGXServiceClient();
//call to the webservice method
GENEius.mgxOptimizationResult result = obj.optimizeSequence(sequence, codonusageId, motifs1);
//returning the result, which is an custom object...
return result; }
Any help would be highly appreciated. If any doubts on the above issue, please feel free to ask.
"mgxOptimizationResult" object is part of teh webservices. I create a object of type "mgxOptimizationResult" and get the result of the web service method call, into this object as shown here.
mgxOptimizationResult result = obj.optimizeSequence(sequence, codonusageId, motifs);
And I'm sure "mgxOptimizationResult" class is serialized as it is part of a web service. I added the web reference to this web service and I have the below in my reference.cs class
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://webserviceSOAP/")] public partial class mgxOptimizationResult {
I'm adding further information here for your understanding...
My "Hello" method (or) base method looks like this
namespace BLogicLibrary { public class BLogic {
public static string Hello(string sequence, string codonusageId, string motifs ) { System.Web.Script.Serialization.JavaScriptSerializer jSerializer = new JavaScriptSerializer(); string[] motifs1 = new string[1]; motifs1[0] = motifs;
//proxy object creation for the web service
MGXServiceClient obj = new MGXServiceClient();
//Method call and storing into the result object (mgxOptimizationResult) mgxOptimizationResult result = obj.optimizeSequence(sequence, codonusageId, motifs1); return jSerializer.Serialize(result); }
}
}
The result object (mgxOptimizationResult) from the Hello method would be serialized to "json", and sent to the callback method @ Ajax. the mgxoptimization class looks like the below:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://webserviceSOAP/")] public partial class mgxOptimizationResult {
Umbraco: /base method call should return an custom created object. But on my callback, I get an xmlDocument Object.
Hi,
I use /base call to call an web services. I dont have .asmx exposed with me. I have the wsdl file only. Hence I cannot use Jquery to call the .asmx method.
hence i go for /base in umbraco. I coded the web service call in my dll. and kept inside /bin of umbraco. And I configured the restExtensions to enable the method to access. Also I could access the method in the base, using javascript as follows.
$.get("/base/BLogic/Hello/" + sequence + "/" + optimization + "/" + motifs + ".aspx",
function (data) {
alert("Call Succ");
alert(data);
});
});
Here "Hello" is the base method name, which takes 3 parameters (Sequence, optimization, motifs), which I could pass. But the return value "data" is an custom object which is returned by the base method. I need to read the "data" and get my values back in javascript. But I get an "object xmlDocument", when i alert "data". Can anyone tell me how to read the values in "data".??
And this is my base method:
public static mgxOptimizationResult Hello(string sequence, string codonusageId, string motifs )
{
string[] motifs1 = new string[1];
motifs1[0] = motifs;
//webservice proxy object creation
GENEius.MGXServiceClient obj = new MGXServiceClient();
//call to the webservice method
GENEius.mgxOptimizationResult result = obj.optimizeSequence(sequence, codonusageId, motifs1);
//returning the result, which is an custom object...
return result;
}
Any help would be highly appreciated. If any doubts on the above issue, please feel free to ask.
I think you must return a serialized object (to get a JSON Object)
public static String Hello(string sequence, string codonusageId, string motifs)
{
....
return new JavaScriptSerializer().Serialize(result);
}
Ok, But can i Serialize the "result" object which is of type "mgxOptimizationResult"??
//call to the webservice method
GENEius.mgxOptimizationResult result = obj.optimizeSequence(sequence, codonusageId, motifs1);
And even if i serialize the "result", Can you please tell me how do i get the results back in my JQuery here below?
$.get("/base/BLogic/Hello/" + sequence + "/" + optimization + "/" + motifs + ".aspx",
function (result) {
alert("Call Succ");
alert(result);
//Please tell me How to read/parse the json object here ??
});
});
My "result" would look like this:
optimizedSequenceOK : Bool (type)
optimizedSequence: String (type)
codonfreqComparisons: MGXcodonfreqcomparisons[]
Where MGXcodonfreqcomparisons would incude:
codon: string
freqOptimal: double
freqBefore: double
freqAfter: double
Yes you can serialize your object mgxOptimizationResult if it look like this (but I did't test this):
[Serializable]
public class mgxOptimizationResult
{
public Boolean optimizedSequenceOK;
public String optimizedSequence;
....
}
public class MGXServiceClient
{
public mgxOptimizationResult optimizeSequence(String sequenze, ...)
{
mgxOptimizationResult mgr = new mgxOptimizationResult();
mgr.optimizedSequence = sequenze;
......
return mgr;
}
}
To get the correct json object you can try this:
$.ajax({
type: 'POST',
url: "/base/BLogic/Hello/" + sequence + "/" + optimization + "/" + motifs + ".aspx",
dataType: 'json',
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
success: function (result) {
alert("Call Succ");
alert(result);
}
});
And your restExtensions.config should look like this:
<ext assembly="yourassembly" type="yourtype" alias="youralias">
<permission method="Hello" returnXml="false" allowAll="true" />
</ext>
Yes, Calvin
"mgxOptimizationResult" object is part of teh webservices. I create a object of type "mgxOptimizationResult" and get the result of the web service method call, into this object as shown here.
mgxOptimizationResult result = obj.optimizeSequence(sequence, codonusageId, motifs);
And I'm sure "mgxOptimizationResult" class is serialized as it is part of a web service. I added the web reference to this web service and I have the below in my reference.cs class
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://webserviceSOAP/")]
public partial class mgxOptimizationResult {
private mgxCodonFreqComparison[] codonFreqComparisonsField;
private string optimizedSequenceField;
private bool optimizedSequenceOKField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("codonFreqComparisons", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
public mgxCodonFreqComparison[] codonFreqComparisons {
get {
return this.codonFreqComparisonsField;
}
set {
this.codonFreqComparisonsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string optimizedSequence {
get {
return this.optimizedSequenceField;
}
set {
this.optimizedSequenceField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public bool optimizedSequenceOK {
get {
return this.optimizedSequenceOKField;
}
set {
this.optimizedSequenceOKField = value;
}
}
}
Anyway i will try the above steps mentioned by you and update you if any success. thanks for you reply. And I hope i could solve this problem.
I'm adding further information here for your understanding...
My "Hello" method (or) base method looks like this
namespace BLogicLibrary
{
public class BLogic
{
public static string Hello(string sequence, string codonusageId, string motifs )
{
System.Web.Script.Serialization.JavaScriptSerializer jSerializer = new JavaScriptSerializer();
string[] motifs1 = new string[1];
motifs1[0] = motifs;
//proxy object creation for the web service
MGXServiceClient obj = new MGXServiceClient();
//Method call and storing into the result object (mgxOptimizationResult)
mgxOptimizationResult result = obj.optimizeSequence(sequence, codonusageId, motifs1);
return jSerializer.Serialize(result);
}
}
}
The result object (mgxOptimizationResult) from the Hello method would be serialized to "json", and sent to the callback method @ Ajax. the mgxoptimization class looks like the below:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://webserviceSOAP/")]
public partial class mgxOptimizationResult {
private mgxCodonFreqComparison[] codonFreqComparisonsField;
private string optimizedSequenceField;
private bool optimizedSequenceOKField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("codonFreqComparisons", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
public mgxCodonFreqComparison[] codonFreqComparisons {
get {
return this.codonFreqComparisonsField;
}
set {
this.codonFreqComparisonsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string optimizedSequence {
get {
return this.optimizedSequenceField;
}
set {
this.optimizedSequenceField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public bool optimizedSequenceOK {
get {
return this.optimizedSequenceOKField;
}
set {
this.optimizedSequenceOKField = value;
}
}
}
Anyway i will try the above steps mentioned by you and update you if any success. thanks for you reply. And I hope i could solve this problem.
My Ajax call looks like below:
$.ajax({
type: 'POST',
url: "/base/BLogic/Hello/" + sequence + "/" + optimization + "/" + motifs + ".aspx",
dataType: 'json',
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
success: function (result) {
alert("Call Succ");
alert(result);
}
});
my restExtension file looks like below
<ext assembly="/BLogicLibrary" type="BLogicLibrary.BLogic" alias="BLogic">
<permission method="Hello" allowAll="true" returnXml="false"/>
<permission method="PersistValuesOfGeneDefinition" allowAll="true" returnXml="true" />
<permission method="CallToGENEius" allowAll="true" returnXml="false"/>
<permission method="matchResourceKeyWithList" allowAll="true" returnXml="false"/>
</ext>
is working on a reply...