繁体   English   中英

从Web服务调用脚本

[英]Calling a script from a web service

如何在Web服务中调用此脚本? 我已经建立了链接,我只需要指向正确方向的代码即可,因为我之前从未对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");
            }


    }
}

您应该研究基本的Web服务操作方法。

简而言之,您的Web服务最终将在“ URL”上运行。 从代码创建对Web服务的服务引用时,您将引用此URL作为服务地址。 然后,您可以调用Web服务上公开的方法(即,通过一种方法调用应在Web服务中公开的代码。)

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

您的Web服务公开方法,并以单独/远程的形式创建对该Web服务的引用,并通过该引用调用其方法。

右键单击您的项目,然后选择“添加服务引用”,以创建对Web服务的引用。 您指定有关Web服务位置的详细信息,并获得对该Web服务的引用。

Dim myWebService as new WebserviceReferenceAdded
myWebService.<method>

暂无
暂无

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

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