getting the response from te webservice

S

steve

hi,

I'm submitting a form to an webservice and like to now how to get te
responce from a webservice?

I'm using c# and infopath 2007 vsta to submit the webservice
public void FormEvents_Submit(object sender, SubmitEventArgs e)
{

WebServiceConnection objWebService =
(WebServiceConnection)this.DataConnections["webservice2"];
objWebService.Execute();
e.CancelableArgs.Cancel = false;

}


the webservice looks like:
[WebMethod(Description = "Webservice2")]
public string webservice2(frm.form2 objform)
{
.....
return "Test"

}

How do i get the string "Test" back to the InfoPath form?

thanks
 
B

Bryan Phillips

This is the code I use to call a web service that returns XML and use it
in the code behind of an InfoPath form:

private XmlDocument GetListData(string dataConnectionName) {
DateTime beginTime = DateTime.Now;

// Create the XmlDocument to accept the query results.
XmlDocument outputFile = new XmlDocument();

if (FormState[dataConnectionName] != null) {

outputFile.LoadXml(FormState[dataConnectionName].ToString());
return outputFile;
}

outputFile.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"
?><outputRoot></outputRoot>");

// Create XmlNamespaceManager for XmlDocument object. When
// creating a more complex document, use AddNamespace method
// to add a mapping from namespace prefix to namespace URL
for
// each namespace to this object.
XmlNamespaceManager outputFileNamespaceManager = new
XmlNamespaceManager(outputFile.NameTable);

// Create an XPathNavigator positioned at the root of the
// XmlDocument output file created above.
XPathNavigator outputFileNavigator =
outputFile.CreateNavigator();
XPathNavigator outputRootNavigator =
outputFileNavigator.SelectSingleNode("/outputRoot",
outputFileNamespaceManager);

// Query the SharePoint list defined for the
// SharepointListQueryConnection and log the results
// in the XmlDocument created above.
SharepointListQueryConnection dataConnection =
this.DataConnections[dataConnectionName] as
SharepointListQueryConnection;
dataConnection.Execute(outputRootNavigator);

FormState[dataConnectionName] = outputFile.OuterXml;

TimeSpan ellapsedTime = DateTime.Now - beginTime;
Debug.WriteLine("GetListData ran in " +
ellapsedTime.Milliseconds.ToString() + " milliseconds.");
return outputFile;
}

--
Bryan Phillips
MCT, MCSD, MCDBA, MCSE
Microsoft MVP - Client Application Development
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net
 
S

steve

hi,

Thanks for the code:
The dataConnectionName is this the name of an submit dataconnetction?
I seem to get a error on the
outputFile.LoadXml(FormState[dataConnectionName].ToString()); code, is it
possible to explane what the code does?
What should is the results from formstate[datConnectionName].ToString() ?
When do you call your code after te submit or wen the submit is in progress?

Does the result from the webservice


Bryan Phillips said:
This is the code I use to call a web service that returns XML and use it
in the code behind of an InfoPath form:

private XmlDocument GetListData(string dataConnectionName) {
DateTime beginTime = DateTime.Now;

// Create the XmlDocument to accept the query results.
XmlDocument outputFile = new XmlDocument();

if (FormState[dataConnectionName] != null) {

outputFile.LoadXml(FormState[dataConnectionName].ToString());
return outputFile;
}

outputFile.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"
?><outputRoot></outputRoot>");

// Create XmlNamespaceManager for XmlDocument object. When
// creating a more complex document, use AddNamespace method
// to add a mapping from namespace prefix to namespace URL
for
// each namespace to this object.
XmlNamespaceManager outputFileNamespaceManager = new
XmlNamespaceManager(outputFile.NameTable);

// Create an XPathNavigator positioned at the root of the
// XmlDocument output file created above.
XPathNavigator outputFileNavigator =
outputFile.CreateNavigator();
XPathNavigator outputRootNavigator =
outputFileNavigator.SelectSingleNode("/outputRoot",
outputFileNamespaceManager);

// Query the SharePoint list defined for the
// SharepointListQueryConnection and log the results
// in the XmlDocument created above.
SharepointListQueryConnection dataConnection =
this.DataConnections[dataConnectionName] as
SharepointListQueryConnection;
dataConnection.Execute(outputRootNavigator);

FormState[dataConnectionName] = outputFile.OuterXml;

TimeSpan ellapsedTime = DateTime.Now - beginTime;
Debug.WriteLine("GetListData ran in " +
ellapsedTime.Milliseconds.ToString() + " milliseconds.");
return outputFile;
}

--
Bryan Phillips
MCT, MCSD, MCDBA, MCSE
Microsoft MVP - Client Application Development
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net



hi,

I'm submitting a form to an webservice and like to now how to get te
responce from a webservice?

I'm using c# and infopath 2007 vsta to submit the webservice
public void FormEvents_Submit(object sender, SubmitEventArgs e)
{

WebServiceConnection objWebService =
(WebServiceConnection)this.DataConnections["webservice2"];
objWebService.Execute();
e.CancelableArgs.Cancel = false;

}


the webservice looks like:
[WebMethod(Description = "Webservice2")]
public string webservice2(frm.form2 objform)
{
.....
return "Test"

}

How do i get the string "Test" back to the InfoPath form?

thanks
 

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