post to mdo:service?

Developer
Dec 30, 2010 at 12:24 PM

Anton, 

thanks for the answer on portal-image-size, I was trying an hard way when it was so simple!

I've got a new question: is it possible to make POST calls to an mdo:service? 

I'm doing some tests with ajaxForm, and have a simple xml mdo:service I wish to call to submit a form. If I use $.get() it all works, but I see errors if I try $.post():

System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space)
at System.Xml.Xsl.Runtime.XmlQueryContext.ConstructDocument(Object dataSource, String uriRelative, Uri uriResolved)
at System.Xml.Xsl.Runtime.XmlQueryContext..ctor(XmlQueryRuntime runtime, Object defaultDataSource, XmlResolver dataSources, XsltArgumentList argList, WhitespaceRuleLookup wsRules)
at System.Xml.Xsl.Runtime.XmlQueryRuntime..ctor(XmlQueryStaticData data, Object defaultDataSource, XmlResolver dataSources, XsltArgumentList argList, XmlSequenceWriter seqWrt)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
at System.Xml.Xsl.XmlILCommand.Execute(XmlReader contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
at System.Xml.Xsl.XslCompiledTransform.Transform(XmlReader input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
at Findy.XsltDb.Transformer.DoTransform(XslCompiledTransform t, XmlReader xr, XsltArgumentList xslArg, StringWriter sw) in d:\inetpub\wwwroot\albe.ihnet.it.dnn\App_Code\XsltDb\XsltDbUtils.cs:line 1232
at Findy.XsltDb.Transformer.TransformRelease(String xml, String xsl, Helper h, String html, Boolean IsSuper) in d:\inetpub\wwwroot\albe.ihnet.it.dnn\App_Code\XsltDb\XsltDbUtils.cs:line 1010
at Findy.XsltDb.Transformer.JustTransform(String xsl, String xml, Boolean debug, Boolean IsSuper) in d:\inetpub\wwwroot\albe.ihnet.it.dnn\App_Code\XsltDb\XsltDbUtils.cs:line 638
at Findy.XsltDb.Transformer.ExecuteService(String xsl, String xml, String serviceName, Boolean IsSuper) in d:\inetpub\wwwroot\albe.ihnet.it.dnn\App_Code\XsltDb\XsltDbUtils.cs:line 619
at ASP.desktopmodules_xsltdb_ws_aspx.Execute() in d:\inetpub\wwwroot\albe.ihnet.it.dnn\DesktopModules\XsltDb\ws.aspx:line 114
at ASP.desktopmodules_xsltdb_ws_aspx.Page_Load(Object sender, EventArgs e) in d:\inetpub\wwwroot\albe.ihnet.it.dnn\DesktopModules\XsltDb\ws.aspx:line 38

Cannot understand what is causing this error: needed parameters (mod and service) are passed.

I'm using 02.00.20.

 

Developer
Dec 30, 2010 at 3:36 PM

I found something about this: first of all, mdo-service can handle POST (of course ;-)).

I get the error only if I try to call jQuery.post() with two parameters, url and data - if I add post parameters to the url it works.

That is this fails with the error from ws.aspx:

 

<xsl:variable name="action">{{mdo:service-url('Taconite')}}<![CDATA[&]]>action=submit</xsl:variable>

<script type="text/javascript">

jQuery.post('{{$action}}', queryString);

</script>

{{mdo:service-url('Taconite')}}<![CDATA[&]]>action=submit

while this works:

<xsl:variable name="action">{{mdo:service-url('Taconite')}}<![CDATA[&]]>action=submit</xsl:variable>

<script type="text/javascript">

jQuery.post('{{$action}}' + '&amp;' + queryString);

</script>

Still don't know why, but it's not XsltDb's fault.

 

Coordinator
Dec 31, 2010 at 11:10 AM

Actually, this is XsltDb bug!

XsltDb service treat request body as XML without looking at request's content type.
But $.post sends data as application/x-www-form-urlencoded.
And as far as it is not XML, XsltDb fails trying to parse it as XML.

Here is a workaround:

<xsl:variable name="action">{{mdo:service-url('Taconite')}}<![CDATA[&]]>action=submit</xsl:variable>

<script type="text/javascript">
$.ajax({
  type: 'POST',
  contentType: 'text/xml',
  dataType: 'text',
  url: '{{$action}}',
  data: "<![CDATA[<r><some-value>21212</some-value></r>]]>",
  success: function(data) {
    $('#result').html(data);
  }
});
</script>

<div id="result"/>

<mdo:service name="Taconite">
<span>{{//some-value}}</span>
</mdo:service>



















 

Coordinator
Dec 31, 2010 at 11:12 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.