Passing a parameter to a web service at runtime

C

Codewzrd

I posted this on the http://www.infopathdev.com forums but that site doesn't
get a lot of traffic. Yet. :)

The following works when I am debugging and I update the XML manually as I
step through the code. I do get back a list of orders.

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.
 
A

Andrew Watt [MVP - InfoPath]

I posted this on the http://www.infopathdev.com forums but that site doesn't
get a lot of traffic. Yet. :)

The following works when I am debugging and I update the XML manually as I
step through the code. I do get back a list of orders.

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.

Superficially, at least, the error message indicates that the dfs
namespace prefix is not declared.

Is there a namespace declaration for the namespace URI for which you
are using the dfs namespace prefix?

It will probably look something like this:
xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"

Andrew Watt
MVP - InfoPath
 
C

Codewzrd

Yes it is defined... here is the GetPID.xml created by infopath

<dfs:myFields
xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
xmlns:tns="http://tempuri.org/"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-11-17T14-33-14"
xmlns:_xdns0="http://schemas.microsoft.com/office/infopath/2003/changeTracking"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"><dfs:queryFields><tns:GetPIDs><tns:nRID></tns:nRID></tns:GetPIDs></dfs:queryFields><dfs:dataFields><tns:GetPIDsResponse><tns:GetPIDsResult><NewDataSet><Table><idxProduct></idxProduct></Table></NewDataSet></tns:GetPIDsResult></tns:GetPIDsResponse></dfs:dataFields></dfs:myFields>

As you can see the dfs is specified as the first definition.

Maybe you could give an example of how to write the value to the text field
of the <tns:nRID>my_value_here</tns:nRID> node? Like I said above, I was
able to add the value at this location and I was able to get the Product
IDs(PID).

Thanks for your help.

Andrew Watt said:
I posted this on the http://www.infopathdev.com forums but that site doesn't
get a lot of traffic. Yet. :)

The following works when I am debugging and I update the XML manually as I
step through the code. I do get back a list of orders.

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.

Superficially, at least, the error message indicates that the dfs
namespace prefix is not declared.

Is there a namespace declaration for the namespace URI for which you
are using the dfs namespace prefix?

It will probably look something like this:
xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"

Andrew Watt
MVP - InfoPath
 
C

Codewzrd

Never mind I figured it out. After doing more research, I was able to figure
out that I am supposed to use IXMLDOMDocument3. No where in any of the
documentation that I have read does it say to use IXMLDomDocument3! Aargh!!!

So all I did was (C#):
DataObject objDO = null;
objDO = thisXDocument.DataObjects["GetProductsID"];
IXMLDOMDocument3 domXML = (IXMLDOMDocument3) objDO.DOM;

Then I was able to see the setProperty and I set the Namespace to the ones I
needed and it all worked!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top