简体   繁体   中英

Calling a script from a web service

How could I call this script within a Web Service? I've already made the link i just need a point in the right direction for the code as I've never done anything with web services before.

namespace WebServiceTranslator
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private Dictionary<string, string> _dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); 

            protected void Page_Load(object sender, EventArgs e)
            {
                using (var reader = new StreamReader(File.OpenRead(@"C:/dictionary.csv")))
                {
                    while (!reader.EndOfStream)
                    {
                        string[] tokens = reader.ReadLine().Split(';');
                        _dictionary[tokens[0]] = tokens[1];
                    }
                }
            }


            public string Translate(string input)
            {
                string output;
                if (_dictionary.TryGetValue(input, out output))
                    return output;
                throw new Exception("There is no meaning for this");
            }


    }
}

You should look into basic webservices howto's.

In a nutshell, your webservice will eventually run at a "url". You will reference this URL as the service address when creating a service reference to the webservice from your code. You can then make calls to the methods exposed on the webservice (IE, call your code that should be exposed in your webservice through a method.)

http://support.microsoft.com/kb/301273

Your webservice exposes methods, and on a separate / remote form, you create a reference to the webservice, and call its methods through this reference.

Create a reference to your webservice by right clicking on your project, and choosing "Add Service Reference". You the specify the details on where your webservice is, and you get a reference to the webservice.

Dim myWebService as new WebserviceReferenceAdded
myWebService.<method>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM