how to read data coming from a web service

S

Stanley

Hi,

i have created the WhoAmI web service to get the username of the current
user using the form. I have added a textbox to the form and bound this to the
secondary datasource which is the whoami web service.
In the on load event of the form i retrieve the username and based on the
user i do something. But appearantly in the on load event this datasource has
not yet been fired so the username has not been retrieved when i want to do
the conditional action.
SO i tried to solve this by executing the datasource in code and retrieve
the username through the DOM with following code:

thisXDocument.DataObjects["GetUser"].Query();
ADOAdapterObject adapt =
(ADOAdapterObject)thisXDocument.DataObjects["GetUser"].QueryAdapter;

IXMLDOMDocument3 oSecondDoc =
(IXMLDOMDocument3)thisXDocument.DataObjects["GetUser"].DOM;
oSecondDoc.setProperty("SelectionNamespaces","xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"
xmlns:d=\"http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\"");
IXMLDOMNode oSecDocNode =
oSecondDoc.selectSingleNode("/dfs:myFields/dfs:dataFields");

//loop through oSecDocNode:
foreach (IXMLDOMNode oN in oSecDocNode.childNodes)
{
if (oN.nodeType == DOMNodeType.NODE_ELEMENT)
{
strUser = oN.selectSingleNode("@UserName").text;
}
}

But than i get a cast error. So can't i cast a sec. datasource which is a
web service to an "ADOAdapterObject"? How can i read this web service?

Thnx,

Stanley
 
S

Stanley

i solved it by not using the data connection but by just setting a web
refenence and using the web service in code.
 
V

virgul

Hi,

Instead of ADoAdaptateur use:

thisXDocument.DataObjects["GetUser"].Query();
IXMLDOMDocument2 oDomSearchHRG =
(IXMLDOMDocument2)thisXDocument.GetDOM("GetUser");
oSecondDoc.setProperty("SelectionNamespaces","xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"");

IXMLDOMNode oSecDocNode =
oSecondDoc.selectSingleNode("/dfs:myFields/dfs:dataFields");
//loop through oSecDocNode:
foreach (IXMLDOMNode oN in oSecDocNode.childNodes)
{
if (oN.nodeType == DOMNodeType.NODE_ELEMENT)
{
strUser = oN.selectSingleNode("@UserName").text;
}
}

hope this help

++

Thierry
 
S

Stanley

Thnx for your response. But i think i will stick with the web service
solution i have tried. Or do you suggest using the dataconnection of IP
instead? Are there advantages/disadvantages using a a direct web service
connection instead through the data connection?

Thnx,

Stanley
 

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