【问题标题】:call remote webmethod from c#从 C# 调用远程 Web 方法
【发布时间】:2013-08-01 13:43:41
【问题描述】:

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

我只有 Testing.asmx 中的这个简单的网络方法。

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

谁能告诉我如何调用这个网络方法(网址:http://mydomain.com/Testing.asmx/TestPdf)?

我想将一个 pdf 文件和一个字符串参数传递给 web 方法,并能够在返回“hello world”之前检索它。

【问题讨论】:

标签: c# asmx webmethod


【解决方案1】:

对于这种用法,必须启用 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);
    }
}

【讨论】:

猜你喜欢
  • 2012-03-31
  • 2012-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-28
  • 2023-04-11
  • 2012-04-09
相关资源
最近更新 更多