从c#调用远程webmethod

时间:2013-07-31 20:33:53

标签: c# asmx webmethod

我想从另一台服务器上的页面后面的代码调用远程webmethod(asmx)。 第二个要求是能够将一个字符串和一个pdf文件传递给webmethod并在web方法中使用它们。

我所拥有的只是Testing.asmx中的这个简单的web方法。

[WebMethod]
public string TestPdf()
{
    return "Hello World";
}

任何人都可以告诉我如何调用这个webmethod(网址:http://mydomain.com/Testing.asmx/TestPdf)?

我想将pdf文件和字符串参数传递给webmethod,并且能够在返回" hello world"之前检索它。

1 个答案:

答案 0 :(得分:0)

对于此用法,必须启用httpget。

private void DownloadInformation()
{
WebClient Detail = new WebClient();
Detail.DownloadStringCompleted += new        DownloadStringCompletedEventHandler(DownloadStringCallback2);
Detail.DownloadStringAsync(new Uri("http://link/"));
 }

private static void DownloadStringCallback2 (Object sender, DownloadStringCompletedEventArgs e)
{
    // If the request was not canceled and did not throw 
    // an exception, display the resource. 
    if (!e.Cancelled && e.Error == null)
    {
        string textString = (string)e.Result;

        Console.WriteLine (textString);
    }
}
相关问题