Web service with an input param via code - Solved - InfoPath Dev
in

InfoPath Dev

Web service with an input param via code - Solved

Last post 05-31-2005 10:52 AM by smcnary. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 11-18-2004 07:10 AM

    Web service with an input param via code - Solved

    A user selects the the customer id from the drop down list box. I take the ID and want to pass it to a web service method programmatically. I tried to store the ID in the data source's XML as a text value but I keep getting an error:"Reference to undeclared namespace prefix: 'dfs'".

    Here is the code that I have so far:

    [InfoPathEventHandler(MatchPath="/my:myFields/my:field1", EventType=InfoPathEventType.OnAfterChange)]
    public void field1_OnAfterChange(DataDOMEvent e)
    {
    // Write code here to restore the global state.
    if (e.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }

    // A field change has occurred and the DOM is writable. Write code here to respond
    // to the changes.

    DataObject objDO = null;
    objDO = thisXDocument.DataObjects["GetPIDs"];

    IXMLDOMNode QueryInput = objDO.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/s0:GetPIDs/s0:nRID" );
    IXMLDOMNode RidNode = thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1");

    QueryInput.text = RidNode.text;
    objDO.Query();
    }


    It's failing on the QueryInput = objDO.DOM.selectSingleNode line. I've read that you may have to set the Namespace before I can select a node, by using the setProperty property of the DOM. But there is no such property.

    Any code example or ideas would be greatly appreciated.
  • 11-18-2004 12:45 PM In reply to

    Re: Web service with an input param via code - Solved

    Never mind again. Figured it out. After oh 4 hours of researching.

    It turns out that I should have been using IXMLDOMDocument3. No documentation that I've read so far says I should use the new interface.

    Anyway doing the following will work:

    [InfoPathEventHandler(MatchPath="/my:myFields/my:field1", EventType=InfoPathEventType.OnAfterChange)]
    public void field1_OnAfterChange(DataDOMEvent e)
    {
    // Write code here to restore the global state.
    if (e.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }

    // A field change has occurred and the DOM is writable. Write code here to respond
    // to the changes.

    DataObject objDO = null;
    objDO = thisXDocument.DataObjects["GetPIDs"];

    IXMLDOMDocument3 domXML = (IXMLDOMDocument3) objDO.DOM;
    domXML.setProperty( "SelectionNamespaces", "xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\" " + "xmlns:tns=\"http://tempuri.org/\"");
    IXMLDOMNode QueryInput = objDO.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/tns:GetPIDs/s0:nRID" );
    IXMLDOMNode RidNode = thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1");

    QueryInput.text = RidNode.text;
    objDO.Query();
    }
  • 11-18-2004 01:23 PM In reply to

    Re: Web service with an input param via code - Solved

    Thanx for sharing the solution with us!

    Greg Collins [InfoPath MVP]
  • 11-19-2004 12:57 AM In reply to

    • jonbrave
    • Top 200 Contributor
    • Joined on 10-15-2004
    • United Kingdom
    • Posts 59

    Re: Web service with an input param via code - Solved

    Sorry, I should have posted earlier as I know you have to set the SelectionNamespaces for any & all secondary DOMs before XPath querying. That's all this is. This should probably be pointed to anyone using multi-DOMs, as I've seen questions to this effect elsewhere.

    I have one question. I do not use managed code or "IXMLDOMDocument3", I'm just using MS Script. Since I'm lazy, and I find all the selection namespaces abstruse, I just set my secondaries to whatever my primary is set to, viz:

    XDocument.GetDOM("Secondary").setProperty("SelectionNamespaces",
    XDocument.DOM.getProperty("SelectionNamespaces"));


    Is this OK or wicked? Does it do any harm?
  • 11-19-2004 09:32 AM In reply to

    Re: Web service with an input param via code - Solved

    It doesn't hurt to have extra namespaces set that you are not using. Your solution is rather elegant provided that there are not additional namespaces to account for in the other DOM.

    Greg Collins [InfoPath MVP]
  • 05-31-2005 10:49 AM In reply to

    Re: Web service with an input param via code - Solved

    Thanks for this solution! Is there any way to convert this code to VB.NET? Thanks! Sarah
  • 05-31-2005 10:51 AM In reply to

    Re: Web service with an input param via code - Solved

    quote:
    Originally posted by CodeWzrd

    A user selects the the customer id from the drop down list box. I take the ID and want to pass it to a web service method programmatically. I tried to store the ID in the data source's XML as a text value but I keep getting an error:"Reference to undeclared namespace prefix: 'dfs'".

    Here is the code that I have so far:

    [InfoPathEventHandler(MatchPath="/my:myFields/my:field1", EventType=InfoPathEventType.OnAfterChange)]
    public void field1_OnAfterChange(DataDOMEvent e)
    {
    // Write code here to restore the global state.
    if (e.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }

    // A field change has occurred and the DOM is writable. Write code here to respond
    // to the changes.

    DataObject objDO = null;
    objDO = thisXDocument.DataObjects["GetPIDs"];

    IXMLDOMNode QueryInput = objDO.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/s0:GetPIDs/s0:nRID" );
    IXMLDOMNode RidNode = thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1");

    QueryInput.text = RidNode.text;
    objDO.Query();
    }


    It's failing on the QueryInput = objDO.DOM.selectSingleNode line. I've read that you may have to set the Namespace before I can select a node, by using the setProperty property of the DOM. But there is no such property.

    Any code example or ideas would be greatly appreciated.

  • 05-31-2005 10:52 AM In reply to

    Re: Web service with an input param via code - Solved

    Thanks for this solution! Is there any way you can convert this code to VB.NET? Thanks, Sarah


    quote:
    Originally posted by smcnary

    quote:
    Originally posted by CodeWzrd

    A user selects the the customer id from the drop down list box. I take the ID and want to pass it to a web service method programmatically. I tried to store the ID in the data source's XML as a text value but I keep getting an error:"Reference to undeclared namespace prefix: 'dfs'".

    Here is the code that I have so far:

    [InfoPathEventHandler(MatchPath="/my:myFields/my:field1", EventType=InfoPathEventType.OnAfterChange)]
    public void field1_OnAfterChange(DataDOMEvent e)
    {
    // Write code here to restore the global state.
    if (e.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }

    // A field change has occurred and the DOM is writable. Write code here to respond
    // to the changes.

    DataObject objDO = null;
    objDO = thisXDocument.DataObjects["GetPIDs"];

    IXMLDOMNode QueryInput = objDO.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/s0:GetPIDs/s0:nRID" );
    IXMLDOMNode RidNode = thisXDocument.DOM.selectSingleNode("/my:myFields/my:field1");

    QueryInput.text = RidNode.text;
    objDO.Query();
    }


    It's failing on the QueryInput = objDO.DOM.selectSingleNode line. I've read that you may have to set the Namespace before I can select a node, by using the setProperty property of the DOM. But there is no such property.

    Any code example or ideas would be greatly appreciated.



Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.