So for the past month I have been working hard on pulling data from a odbc driver/connection. That was easy. Then I was tasked to pass a parameter to the blessed thing and clean up the XML transaction. Ok Here is how it works:
So earlier I posted how to get all data from a web method and then filter it with another web method.
Oh Tedious thy name is vain. Huh?
Moving forward. There is three examples of a web service that uses XML doc type as a string to allow **Key Word Here**
PARAMETERS.
1: using System;
2: using System.Data;
3: using System.Data.SqlClient;
4: using System.Web;
5: using System.Web.Services;
6: using System.Web.Services.Protocols;
7: using System.Data.Odbc;
8: using System.Data.OleDb;
9: using System.Xml.Schema;
10: using System.Xml;
11:
12:
13: [WebService(Namespace = "http://localhost")]
14: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
15: public classYOURDSNService : System.Web.Services.WebService
16: { 17: public YOURDSNService ()
18: { 19: }
20: [WebMethod]
21: public XmlDocument GetAllYourTable()
22: { 23: XmlDocument doc = new XmlDocument();
24: DataSet YourTableDataSet = new DataSet("YourTable"); 25: using (OdbcConnection conn = new OdbcConnection("Dsn=YOURDSN;uid=Hello;pwd=Moto")) 26: { 27: OdbcDataAdapter adapter = new OdbcDataAdapter("Select * from PUB.YourTable WHERE Brand ='Hello_kitty' AND Shipped = 0", conn); 28: adapter.Fill(YourTableDataSet, "YourTable");
29: }
30: doc.LoadXml(YourTableDataSet.GetXml());
31: return doc;
32: }
33:
34: //That was interesting but not very Filtered.
35:
36:
37:
38: [WebMethod]
39: public XmlDocument GetStringbyStringName(string x)
40: { 41: XmlDocument doc = new XmlDocument();
42: DataSetYourTableDataSet = new DataSet("YourTable"); 43: using (OdbcConnection conn = new OdbcConnection("Dsn=YourDSN;uid=Hello;pwd=moto")) 44: { 45: OdbcDataAdapter adapter1 = new OdbcDataAdapter("Select * from PUB.YourTable Where fieldname = '" + x + "'", conn); 46: adapter1.Fill(YourTableDataSet, "YourTable");
47: }
48: doc.LoadXml(YourTableDataSet.GetXml());
49: return doc;
50: }
51: [WebMethod]
52: public XmlDocument Getfieldfromstring(string y)
53: { 54: XmlDocument doc = new XmlDocument();
55: DataSet YourTableDataSet = new DataSet("YourTable"); 56: using (OdbcConnection conn = new OdbcConnection("Dsn=YOURDSN;uid=hello;pwd=moto")) 57: { 58: OdbcDataAdapter adapter1 = new OdbcDataAdapter("Select * from PUB.YourTable Where field = '" + y + "'", conn); 59: adapter1.Fill(YourTableDataSet, "YourTable");
60: }
61: doc.LoadXml(YourTableDataSet.GetXml());
62: return doc;
63: }
64: }
Wowie wow! That is it.... Ah the fun and love of it.
And if you want to speed up your slooow webservice take a look at what you can do to your webmethod to make it kinda fast.
[System.Web.Services.WebMethod(EnableSession = false, CacheDuration =30, BufferResponse = true)]