Solved

Filling a Windows Froms Combo Box From a .Net Web Service

Posted on 2006-07-14
8
172 Views
Last Modified: 2011-09-20
Hi All,

I am developing a VB.Net app that uses a SQL Server Backend, a .Net Web Service as the middle tier and a VB.Net Windows Forms app as the front end.  It seems that everyone assumes that if you are using a Web service that your front end will be ASPX or at least browser based.  To date I have not been able to find a single example that shows a web service consumed by a Windows forms app.  (I digress here only to ask that if anyone knows of a good resource for Web service to Windows Forms app info please include. – this includes Books, Web sites, and Magazines etc.)

Ok, now on to the meat so to speak.  I have a Customer class in my web service; it contains the usual stuff Name, address etc.  I have a web method GetCustomer that will return a class Customer if you provide the Customer ID.  (The Customer Class has all the necessary code to retrieve a customer from the backend.)

Now that works but I cannot find any windows forms examples on how to return a list of Names and customer ID’s to load into a combo so the user can select a customer by name.

I tried creating a collection with just Name and ID as properties.  But it will not show up as a web method. And any examples seem to state that I must include the code for the entire collection in my front end to even think about using it.  (didn’t have to do that for the class!?!)

Thought about using a List array but I can’t find any examples that aren’t ASPX based.
Besides, I like the whole collection idea better because it seems cleaner to me.

I’m giving out 500 points for this question because I think this will become a running dialog over the next few days.

Help?

Thanks in advance!
0
Comment
Question by:mnichols1202
  • 5
  • 2
8 Comments
 
LVL 8

Expert Comment

by:sagacitysolutions
ID: 17112145
Try this

Add a web reference to your project and go from there

Some documentation:
http://www.codeproject.com/vb/net/vbwebservice.asp

0
 
LVL 4

Expert Comment

by:sr101880
ID: 17124072
Just to be clear,  you are having trouble getting the name and id from your web service or are you having trouble putting the name and id into a combo so the user can select a customer by name?
0
 

Author Comment

by:mnichols1202
ID: 17151417
Both actually,  i have a class called "Customer" with all the usual info and a webmethod "GetCustomer" that take a customer id and returns a class customer (i.e looks up the appropreate data in the backend and returns the customer)
so i created a collection "Customers"  with a simple class with two properties Customer_ID and Name.

So another web method "GetCustomers" should return the collection customers.  however, the collection never shows up in intellisense (remember the Get Customer Web method is working fine - and i've refreshed the web reference)

I've been reading some fleeting passages about Web Services can only return a limited number of simple types....but i can't find anything definitive!!

0
 
LVL 4

Expert Comment

by:sr101880
ID: 17167372
Is your other web method GetCustomers in the same web service or is it in a separte web service?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:sr101880
ID: 17167482
If GetCustomers is in the same web service did you declare the method using "Public" like the example below?

Public Function GetCustomer( _
 ByVal customerID As String) As DataSet
0
 

Author Comment

by:mnichols1202
ID: 17167632
Yes and Yes again.

The call is
<WebMethod>Public Function GetCustomers() as Customers


and

<WebMethod> Public Function GetCustomer(CustomerID as Long) as Customer

Second one works - first one doesn't even show up in the Client Object list or intellisense
0
 
LVL 4

Accepted Solution

by:
sr101880 earned 500 total points
ID: 17167900
The code you gave above looks correct.  The only thing I can think of is that there isn't  a new instance of customers created before you call the method.

I have found a good example of what you are trying to accomplish for an overall goal.  It is at:  

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/webservicesdcom.asp

All you need to do is select "The xml web service" from the hyperlinks under contents.  It will give you step by step instructions to create the web service and windows app that you are looking for.  :-)

Let me know if you have any questions.
0
 
LVL 4

Expert Comment

by:sr101880
ID: 17175422
mnichols1202,

     Did you find what you were looking for?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now