2013-07-31 89 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