0
votes

I have basic knowledge to create a web service using asmx.cs and consume from any client application. I want to create a Web Service using asmx.cs in .NET 3.5 using Visual Studio 2010. For the following program,By default it gives textBox to take input from user. But I want to use comboBox to take input from the user. The result will be displayed as xml output. I want to do a Web Service program where one city from ComboBox will be taken as input and the temperature will be shown as xml output. This code gives only textBox as input.


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    namespace WebService1
    {
        public class Service1 : System.Web.Services.WebService
        {
            [WebMethod]
            public string GetCityByZip(int Zip)
            {
                return "City Name = XYZ, Temperature = 30 Degree";
            }       
        }
    }

1

1 Answers

0
votes

I think, what you're talking about is this html to test your web service methods, right?

http://3.bp.blogspot.com/_nuQwSyDoLk8/RvWnnpahW8I/AAAAAAAAAJw/UTFuJmCx5M0/s1600-h/WS3.bmp

This test ui is generated automatically based upon your service's WSDL. The input types are based on the methods your service exposes. So if there's a method like CityInfo GetCityInfo(string cityName) in your service, there will be a textbox with input type string (as you already noticed). If you're exposing a method like CityInfo GetCityInfo(int cityId) the input type will be an int.

What's not possible, is to put a combobox there, as the service is autogenerated and has no knowledge which cities are selectable.

What you can do, is expose several methods and build a ui yourself (which you should do anyway).

public interface IYourServiceInterface
{
    City[] GetCities(); // returns all possible cities

    CityInfo GetCityInfo(City city); // returns detail Infos about a concrete city
}