web service method with complex type parameter - InfoPath Dev
in

InfoPath Dev

web service method with complex type parameter

Last post 09-21-2005 12:24 AM by Patrick Halstead. 22 replies.
Page 2 of 2 (23 items) < Previous 1 2
Sort Posts: Previous Next
  • 09-19-2005 05:28 AM In reply to

    Re: web service method with complex type parameter

    Hi,

    I followed your recommendation and now the web service takes a string as a parameter instead of a complex type :

    [WebMethod]
    public bool testInsertion(String s)
    {
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(s);

    try
    {
    string titre = doc.SelectSingleNode("my:insererContenu/my:titre").InnerText;


    with an Infopath SOAP request that looks like this :

    <my:insererContenu xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-08-25T08-37-41">
    <my:titre>titre test</my:titre>
    ...
    </my:insererContenu>


    The problem is, the XmlDocument can't handle elements with "my:" prefix !

    When I debug the web service and try to access the value of doc.SelectSingleNode("my:insererContenu/my:titre"), I get this error :

    System.SystemException. Namespace manager or XsltContext is required. This query has a prefix, a variable, or a user-defined function.

    So it seems that the LoadXML() method doesn't detect the namespace definition contained in the <my:insererContenu> root node...
    Is there a way I can make that work, either by using another method or removing the "my:" prefixes from the SOAP request sent by Infopath ?

    My boss is getting fed up with InfoPath and wants me to change for OpenOffice (which would be far less simple for me), so if you have a solution ;)

    Thanks
  • 09-19-2005 06:52 AM In reply to

    Re: web service method with complex type parameter

    Yeah...the namespace issue will bite you...it has with me in the past. I personally do not like this "my" namespace that InfoPath shoves on you. I would love to sit down and write an article on XSD management with InfoPath in an enterprise. The problem is, which I can see as becoming a problem, is that developers do not see a bigger picture when developing an InfoPath form and the underlying XSD they are building for thier form.

    Two suggestions, and maybe Patrick would like to chime in:

    1 - Check into adding the namespace to your XmlDocument object just like you would in script in InfoPath. Not sure how to do offhand.
    2 - Export the XSD that you currently have in your InfoPath form, and then load it into your XmlDocument object to validate the XML.

    Another thing you can do in the future is to write you own XSD and do not use the one generated by InfoPath. This will allow you to independantly publish and XSD that you can use in InfoPath, Webservice or another layer of your enterprise architecture. There are some Pros and Cons.
    Jason
    http://www.k2distillery.com/
  • 09-19-2005 12:29 PM In reply to

    • Sumeet
    • Not Ranked
    • Joined on 08-25-2005
    • USA
    • Posts 12

    Re: web service method with complex type parameter

    Hi Guys,

    I have been researching this topic for almost three days and this is the way I found to pass a complex type(object) to and from a web-service. Convert it to an XML string and then reconstruct the object on the web-service side from the string and then do stuff and then do the whole process of converting it to a string again and then deserializing the XML string and re-constructing the object.

    A perfect example can be found athttp://www.codeproject.com/soap/XmlToClassAndBack.asp. Remember to add the reference to System.XML.Serialization and [XmlType(Namespace="xyz")] attribute to the class.

    Hope this helps.
  • 09-19-2005 12:40 PM In reply to

    Re: web service method with complex type parameter

    Yes, that is another great approach. Make your .NET classes XML Serializable. I was lead to believe the original implementation of the web service was not in .NET code. Otherwise that great practice.
    Jason
    http://www.k2distillery.com/
  • 09-19-2005 11:03 PM In reply to

    Re: web service method with complex type parameter

    Serialization is good! Yes.

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 09-20-2005 02:05 AM In reply to

    Re: web service method with complex type parameter

    For now I have solved my problem by using a XmlNamespaceManager and referring to it each time I use the SelectSingleNode method :

    [WebMethod]
    public bool testInsertion(String s)
    {
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(s);
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
    nsmgr.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-08-25T08-37-41");

    string titre = doc.SelectSingleNode("my:insererContenu/my:titre", nsmgr).InnerText;
    ...


    It's a bit tiresome but it works.

    Thanks for the serialization suggestion, I'll have a look at it.
  • 09-20-2005 05:25 AM In reply to

    Re: web service method with complex type parameter

    That is a bummer.

    When writing script code in InfoPath you be surprised how many times I would have to write the following code which is doing the same thing as the XmlNamespaceManager class.

    XDocument.DataObjects("data connection").DOM.setProperty("SelectionNamespaces", "xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-21T20:40:37""")

    Glad to hear you were able to get over the hurdle.
    Jason
    http://www.k2distillery.com/
  • 09-21-2005 12:24 AM In reply to

    Re: web service method with complex type parameter

    Why write script? Why not write C# in your InfoPath form?

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
Page 2 of 2 (23 items) < Previous 1 2
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.