Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links


How to use java webservice in windows phone app

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 08-04-2012
Member
 
Join Date: Aug 2010
Posts: 31
How to use java webservice in windows phone app

Sponsored Links
Hello I am using java web-service in windows phone app and for java web-service I have written below codes: I think my code should show output in list-box although my code is not working at all, meaning I have got the list-box but that’s empty and nothing else. So can anyone suggest what need to correct on my code. Below is my code:

Code:
namespace Medical_Representative_Project2, 
{
    public partial class Antocids : PhoneApplicationPage
    {
        ObservableCollection<Class1> p = new ObservableCollection<Class1>();

        ProductsClient client = new ProductsClient();
     
        public Antocids()
        {
            InitializeComponent();
          //  listBox1.DataContext = p;
          
           
          
            client.getProdDetailsAsync();
            client.getProdDetailsCompleted+=new EventHandler<getProdDetailsCompletedEventArgs>(client_getProdDetailsCompleted);
           
        }
        private void client_getProdDetailsCompleted(object sender, getProdDetailsCompletedEventArgs e)
        {
            //listBox1.ItemsSource = p;
        //var prodresult = (from p in e.Result select p).ToList();  //this also not worked
       
            listBox1.ItemsSource=p;
        }
       
        
       
    }
}

Reply With Quote
  #2  
Old 08-04-2012
Member
 
Join Date: Nov 2010
Posts: 72
Re: How to use java webservice in windows phone app

by looking at your code I have found you have not setup any P to and this is empty. I have created the JAVA webservice in windows phone without any issue and if I compare the both code I think you have not added ItemsSource in the constructor and then populate it when the worker is done. So to test this I would like to suggest you to add below code on your code and after that you can solve your issue,
First of build the simple Person class like this:
Code:
class Person
{
    public string Name { get; set; }
}
Now here declare property called "p" which hold ObservableCollection value.
ObservableCollection<Person> p = new ObservableCollection<Person>();
Once you define the P and after that create the Antocids code which given below:

Code:
public Antocids()
{
    InitializeComponent();

    listbox1.ItemsSource = p;

    var worker = new BackgroundWorker();
    worker.DoWork += new DoWorkEventHandler(worker_DoWork);
    worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

    worker.RunWorkerAsync();
}
Now you have enter the below code under client_getProdDetailsCompleted function:

Code:
p.Add(new Person { Name = "Filip Ekberg" });
p.Add(new Person { Name = "Anders Andersson" } );

foreach(var p in e.Result)
{
    p.Add(p);
}
As you have seen my code you need to add BackgroundWorker which help you to simulate the same behavior as you have with your web-service. In short that means you have add "listBox1.ItemsSource = p;" right before "client.getProdDetailsAsync();" and after that you should add in "client_getProdDetailsCompleted" which given below:
foreach(var p in e.Result)

Code:
{
    p.Add(p);
}
Reply With Quote
  #3  
Old 08-04-2012
Member
 
Join Date: Aug 2010
Posts: 31
Re: How to use java webservice in windows phone app

Hello thanks for the replies and I have tried your code but this doesn’t helped me to solve mien issue. When I run your code as you said I have got the below error messages:
Quote:
“The best overloaded method match for 'System.Collections.ObjectModel.Collection<example_app.product>.Add(example_app.product)' has some invalid arguments
//error 2 is Error 2 Argument 1: cannot convert from 'example_app.ServiceReference1.ProdData' to 'example_app.product' “
Now I don’t what to do and how to solve this issue. Can anyone provide me correct code for this..
Reply With Quote
  #4  
Old 08-04-2012
Member
 
Join Date: Dec 2010
Posts: 99
Re: How to use java webservice in windows phone app

Hello your getting this issue due to the ProdData and you should try to convert ProdData to product object and after that you won’t get this issue or error message. Try the below code inside the foreach loop:

Code:
var product = new product { Name = a.Name };
p.Add(product);
if this doesn’t help you to solve your issue and then I would like to suggest you to try the below code as well and I am sure this will help you to solve your issue.

Code:
foreach (var a in e.Result)
{
    p.Add(new product { Name = a.Name} );
}
Here make sure every result in the "e.Results" variable correctly called the Name which you have given.
Reply With Quote
  #5  
Old 08-04-2012
Member
 
Join Date: Aug 2010
Posts: 31
Re: How to use java webservice in windows phone app

Hello thanks for the replies but this I have got the different error message both code are not working. While I have tried the add the code in foreach loop I have got the below error message :
Quote:
p.Add(new product { Name = a.Name });//at a.Name only
'example_app.ServiceReference1.ProdData' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'example_app.ServiceReference1.ProdData' could be found (are you missing a using directive or an assembly reference?)
And I have tried second code but I have got the same issue, nothing working.....
Reply With Quote
  #6  
Old 08-04-2012
Member
 
Join Date: Mar 2011
Posts: 152
Re: How to use java webservice in windows phone app

Hello thanks for posting error code and replying back. I think you’re very close to solve your issue. Ok on code e.Result is an Array of objects and these are ProdData type and you wanted to use this as own type "product". So to solve this I would like to suggest you to try to add and change the below code in ObservableCollection and then you can solve your error codes:

Code:
ObservableCollection<ProdData> p = new ObservableCollection<ProdData>();
And then in your foreach-loop you do this:
foreach (var a in e.Result)
{
    p.Add(a);
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use java webservice in windows phone app"
Thread Thread Starter Forum Replies Last Post
Security between flex+air and webservice Isiah Software Development 5 09-07-2010 03:10 AM
Need a small webservice for my website. Sarah Rogger Technology & Internet 4 15-06-2010 12:21 AM
Parsing XML WebService Efigenio Software Development 4 03-03-2010 02:55 AM
Enable SOAP to webservice Harshini Software Development 1 22-04-2009 11:53 PM
MiPhone M88 Wifi Quadband Pda Smart Phone with Windows Os6.0 & Java monsitj Portable Devices 0 05-01-2009 10:59 AM


All times are GMT +5.5. The time now is 11:07 PM.