简体   繁体   English

从Web服务调用脚本

[英]Calling a script from a web service

How could I call this script within a Web Service? 如何在Web服务中调用此脚本? 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. 我已经建立了链接,我只需要指向正确方向的代码即可,因为我之前从未对Web服务做过任何事情。

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. 您应该研究基本的Web服务操作方法。

In a nutshell, your webservice will eventually run at a "url". 简而言之,您的Web服务最终将在“ URL”上运行。 You will reference this URL as the service address when creating a service reference to the webservice from your code. 从代码创建对Web服务的服务引用时,您将引用此URL作为服务地址。 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.) 然后,您可以调用Web服务上公开的方法(即,通过一种方法调用应在Web服务中公开的代码。)

http://support.microsoft.com/kb/301273 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. 您的Web服务公开方法,并以单独/远程的形式创建对该Web服务的引用,并通过该引用调用其方法。

Create a reference to your webservice by right clicking on your project, and choosing "Add Service Reference". 右键单击您的项目,然后选择“添加服务引用”,以创建对Web服务的引用。 You the specify the details on where your webservice is, and you get a reference to the webservice. 您指定有关Web服务位置的详细信息,并获得对该Web服务的引用。

Dim myWebService as new WebserviceReferenceAdded
myWebService.<method>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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