September 23, 2005

Custom Objects with Web Services

Web Services are not .net specific. Most of them might think its something Microsoft invented. What Microsoft have done is they implemented a common standard. To create a web service in .net is really easy. But you should understand the concept behind it. You can find the public web services which available through Microsoft UDDI service.(http://uddi.microsoft.com/visualstudio/ )

So today im going to explain how to return a custom object through web service. I will explain the scenario from a simple diagram.( banks needs a valid telephone number to issue a credit card its a fact)




















In this scenario Telephone Company is offering a web service to its partners to get the customer just by supplying customers telephone number.

Customer class:

public class Customer
{
public Customer()
{
//
// TODO: Add constructor logic here
//
}

string _name;
string _age;
string _company;

public string Name
{
get{return _name;}
set{_name = value;}
}

public string Age
{
get{return _age;}
set{_age = value;}
}
public string Company
{
get{return _company;}
set{_company = value;}
}
}

GetCustomer web service method which returns the customer object

[WebMethod]
public Customer GetCustomer()
{
//can be perform any database functions

Customer customer = new Customer();
customer.Name = "Ludmal de silva";
customer.Age = "25";
customer.Company = "E-Solutions";

return customer;
}


Now we can use this web service by simply adding a web reference to our project.(you guys should know how to add a web reference its really simple).

Finally you can get the customer object which returns from the web service. Code below.

//Customer object
CustomerService.Customer customer = new CustomerService.Customer();

//CustomerService object
CustomerService.Service1 myCustomerService = new CustomerService.Service1();

///Get the customer from the WebService
customer = myCustomerService.GetCustomer();

//Assigning the values to the UI
this.Label1.Text = customer.Name;
this.Label2.Text = customer.Company ;
this.Label3.Text = customer.Age ;

What I was trying to do is to give a basic idea about web services & to use the custom object with web services. I highly appreciate comments. (my writing skills might be poor...) But all the questions /comments are welcome.

14 comments:

Mahasen said...

It’s a nice piece. Good reading for some one who wants a simple straight forward sample.

My idea is when writing technical artifacts, we should think of what we might want to read at different circumstances. If we are tight in a schedule and want to get some thing done we need some thing like your article, simple and straight forward no bluffs and sweet talks. If we are passionate about a certain technology and want to learn it inside out; then we need detailed clear and long articles. If we just need to get the work done but our work isn’t straight forward we need a FAQ kind of thing… so if we write so serve our need, it would serve some one else’s need as well :)

website design New York City said...

thanks u r information

Anonymous said...

Cool stuff buddy... Awesome..

Manjuke Fernando said...

Very useful.. Short and sweet....

Anonymous said...

My name is Kelly Smith I was browsing internet and found your blog. The author did a great job. I will subscribe to your RSS feeds. Thank you for your contribution. I am a web designer myself. And here some examples of the websites that I designed for loans canada payday loans company.

Custom Software Developer India said...

Hello, it wants new ideas and techniques everytime. thank you for sharing this.

Custom Software Developer India

Smartphone Development said...

i read this entire article. Really felt very happy to see this useful & informative info. Thanks for sharing with us.

Virtual Administrative Assistant said...

I just wanted to add a comment here to mention thanks for you very nice ideas. Blogs are troublesome to run and time consuming thus I appreciate when I see well written material. Your time isn’t going to waste with your posts. Thanks so much and stick with it No doubt you will definitely reach your goals! have a great day!

Melbourne embroidery said...

Interesting and important information. It is really beneficial for us. Thanks

Botox Chicago said...

I’ve learned a lot from your blog here, Keep on going, my friend, I will keep an eye on it,

Fort Lauderdale criminal lawyer said...

Interesting layout on your blog. I really enjoyed reading it and also I will be back to read more in the future.

Fulton Septic Cleaning said...

All that we are is the consequence of what we have estimation. Wait… Has anyone exhorted dissertation to you. Keep the articles progressing !

online auction said...

Interesting and important information. It is really beneficial for us. Thanks

Gainesville apartment said...

This is really an interesting blog as it focuses on the very important topic. i came to know about so many things or tips.