webservice for infopath that can use query fields

D

Depova

I've been working with webservices for a few weeks now and am having
trouble. I've been able to make a web service that will submit to a
sql 2000 database and query from it. Problem is the only query I've
been able to make work returns all results. What I'd like to be able
to do is use query fields in the infopath form. I'm using visual
studio.net 2003 and this walkthrough from microsoft to make the
webservice.

http://msdn.microsoft.com/library/d...y/en-us/odc_ip2003_tr/html/odc_INF_Lab_09.asp

Can someone post code to a sample web service that has this capability
with maybe some instructions, or at least point me someplace where they
show this?

Thanks in advance.
 
B

bratt

Here is some code from my VB app - which could be easily transferred to
c# if needed - basically you add a parameter in the web service that
filters your dataset then from InfoPath you specify the parameter in
the XML that gets sent to the service. The biggest problem is making
sure the names spaces and Xpath's are correct. This code calls my web
service for getting a unique ID.

' dataconnection to my webservice is called: UniqueID
Private Function GetNextUniqueID(Optional ByVal KeyName As String =
"InfopathApp") As String
Try
Dim UniqueID As DataObject = thisXDocument.DataObjects("UniqueID")
Dim domtemplate As IXMLDOMDocument3 = UniqueID.DOM

'Set the SelectionNamespaces so that you can find the correct field
domtemplate.setProperty("SelectionNamespaces", _

"xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"""
& _
"
xmlns:d=""http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"""
& _
"
xmlns:dsf=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"""
& _
" xmlns:ns3=""UniqueIDURI""")

'Set Web Service parameters
domtemplate.selectSingleNode("/dfs:myFields/dfs:queryFields/ns3:UniqueID/ns3:applicationName").text
= KeyName

UniqueID.Query()

' get value from: UniqueIDResponse/UniqueIDResult
Return
domtemplate.selectSingleNode("//dfs:dataFields//UniqueIDResponse//UniqueIDResult").text
Catch ex As Exception
' unique connection is not running - create one and HOPE you are unique
Dim today As Date = Now()
Return today.ToString("yyyyMMddhhmmss")
End Try


in my UniqueID webservice I have an input parameter to filter the
dataset:
<WebMethod()> _
Public Function UniqueID(ByVal ApplicationName As String) As String
'' if you are opening a recordset directly with a sql clause you may
want to check for sql injections:
'' ApplicationName = ApplicationName.Replace("'","''")
'' ...
 

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