Solved

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

Posted on 2006-07-14
8
171 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

12 Experts available now in Live!

Get 1:1 Help Now