Web service, xml, local storage

hello, im very green to .net cf and some help are needed regarding the usage of xml as local storage.

i've used web service to open a connection to database to get the data that i want and convert it into xml. below are the code

<WebMethod()> _
Public Function getStud() As DataSet <-- does this means, im going to return a dataset to the calling application

Dim conn As New SqlConnection("Data Source=localhost;Initial Catalog=Proj;Integrated Security=SSPI")

conn.Open()

Dim da As New SqlDataAdapter("GetStudent", conn)
da.SelectCommand.CommandType = CommandType.StoredProcedure
Dim ds As New DataSet
da.Fill(ds, "Student")
ds.WriteXml("C:\student.xml") <-- how do i change this to store in pocket pc instead of in the desktop

conn.Close()

Return ds <-- im not sure whether returning the ds to the calling application and then only write it to xml file is appropriate.

This is my application code, where i've referred to the web service :

Dim stud As New v1.getFromDb.Service1
Dim ds As New DataSet
'stud.getStud = ds <-- this could not be assigned, error : expression is a value and therfore cannot be a target of an assignment
DataGrid1.DataSource = stud.getStud <-- since the above cannot work, i try to assign it to a datagrid, an exception was caught : A managed Web Exception occured at Application :: Run+Ox1a , unable to connect to remote server

Can anyone please advise me on, whether the approach(web service -> connect db-> convert data to xml-> store in ppc-> use the xml as local storage) that i use is correct or v.v Please provide some sample code as i really have no idea on how to do it.

Many thanks.






Answer this question

Web service, xml, local storage

  • Grant Jenkins

    1. Yes.

    2. You remove that from web method and add it to the client running on device after you call web method and got dataset back. Keep in mind devices don’t have driver letter and don’t support relative paths so “C:\student.xmlwon’t work and needs to be changed.

    3. But of course it could not - it's a function returning dataset, you can't assign anything to a function. It would return dataset if you call it which also means line above creating the dataset is not needed.

    4. The code is correct but you have network connection issue or using localhost as web server name. It's a common mistake - ‘localhost’ means “host I’m running on” so it would work only if you run application on web server itself.

    By the way, generally you don't need all that - just use SQL Client on device to connect to SQL Server directly.



  • neo1000

    Thanks for your response, as it clear some of my confusion. fyi, i've been working on this for few days, and i cant get anything out of it, and its really causing headaches..

    1) if i cannot use localhost, what should i use

    2) what do you mean when you say that, remove it from the web method, and add it to the client running on device meaning,the code ds.writexml("/programfiles/student.xml) put in client app Can you please show me how

    3) how to use sql client on device to connect to sql server directly will it be the same code as i put in web service

    4) regarding the deployment in vs.net 2003, we can choose to either deploy on emulator / real device rite why is it that whenever i try to start with debugging, it is not possible ( i have to start without debugging) and whenever i do some changes to my code, i have to shut down the emulator, and let it load everything all over again when i test. This is taking a lot of time, is there any other way

    5) the app that i am developing targets on disconnected environment The reason i use web service is to get data from the server and transform it into xml file to be consumed as local storage in ppc. Please correct me if the approach i use is wrong,

    (web service-> connect db-> get data-> write to xml file-> client app use web service->save xml in ppc-> manipulate the data (update/ delete) in ppc -> transfer back the xml file to be updated in sql server. )

    you must be wondering why i didnt choose sql mobile as server, as it is far easier than using xml. I am constrained to only use xml and i know nothing about it.. and i know very little about .net cf too...

    Please advice, many thanks...



  • msmuser

    1. You should use actual server name or IP. Just like you tell your address to the taxi driver instead of saying "home, please".

    2. Yes. There's nothing to show, you already have the code.

    3. Yes, same code. Connection string might need some tweaking to include server name, port number and credentials.

    4. Right. Something is probably broken in your VS 2003 installation, normally you should be able to debug just fine – try repairing it. You don't need to restart the emulator, just add menu or button to exit your application so file won't be in use as you need to redeploy.

    5. Sure, that works. Works the same way with direct access to SQL Sever - get data from SQL to dataset, save it to XML, load it back into dataset and update SQL. I don't see why would you write to XML on a web server though and why.



  • Web service, xml, local storage