2013-07-31 58 views
0

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

我所拥有的就是Testing.asmx中的这个简单webmethod。

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

任何人都可以请让我知道如何调用此的WebMethod(网址:http://mydomain.com/Testing.asmx/TestPdf)?

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

+1

看一看的[WebClient类(http://msdn.microsoft.com/en-us/library/system.net.webclient(V = vs.110)的.aspx)。 –

+0

请参阅http://johnwsaunders3.wordpress.com/2009/05/17/how-to-consume-a-web-service/ –

回答

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); 
    } 
} 
+0

我的问题是如何从代码隐藏中调用此webmethod?其次,如何将参数传递给web方法。 – pessi

+0

你的意思是像http://stackoverflow.com/questions/1224672/how-to-call-a-web-service-method? – LosManos