Solved

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

Posted on 2006-07-14
8
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 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