共用方式為


HOW TO:建立 ASP.NET Web Form 用戶端

Code Example

當做 Web 服務用戶端的 ASP.NET Web Form,在參考 Proxy 類別及進行部署的方式上與其他 Web 服務用戶端有所不同。具體來說,您可以從 ASP.NET Web Form 建立組件中的公用類別 (此組件會部署至包含 Web Form 之 Web 應用程式下的 \Bin 目錄)。因此,如果您建立 Web 服務用戶端 Proxy 類別,再編譯成組件,然後將它放在 \Bin 目錄中,那麼 ASP.NET Web Form 就可以建立 Proxy 類別的執行個體。

若要建立 Web 服務的 Web Form 用戶端

  • 建立 Web 服務的 Proxy。

    Wsdl https://www.contoso.com/Counter.asmx?WSDL
    
    Wsdl /language:VB https://www.contoso.com/Counter.asmx?WSDL
    

    如需詳細資訊,請參閱建立 XML Web Service Proxy

將 Web 服務 Proxy 編譯成組件,其中包括 System.Xml.dll 和 System.Web.Services.dll 組件以及在步驟 1 中建立的 Proxy。

csc /out:Counter.dll /t:library /r:System.XML.dll /r:System.Web.Services.dll Counter.cs

範例

 <%@ Page Language="C#" %>
<asp:Label id="Label1"  />
<script runat=server language=c#>

 void Page_Load(Object o, EventArgs e){

  int UsageCount;
  // Create an instance of the Web service class.
  Counter myCounter = new Counter();
  // Call the Web service method ServiceUsage.
  UsageCount = myCounter.ServiceUsage();

  Label1.BackColor = System.Drawing.Color.DarkSlateBlue;
  Label1.ForeColor = System.Drawing.Color.Gold;
  Label1.BorderStyle = System.Web.UI.WebControls.BorderStyle.Inset;

  // Display the results in a Label Web Form server control.
  if (UsageCount == 1)
       Label1.Text ="Web service has been utilized >" + UsageCount.ToString() + "< time.";
  else   
       Label1.Text= "Web service has been utilized >" + UsageCount.ToString() + "< times.";
}
</script>
<%@ Page Language="VB" %>
<asp:Label id="Label1"  />
<script runat=server language="VB">

Sub Page_Load(o As Object, e As EventArgs)
    Dim UsageCount As Integer
    ' Create an instance of the Web service class.
    Dim myCounter As New Counter()
    ' Call the Web service method ServiceUsage.
    UsageCount = myCounter.ServiceUsage()
    
    Label1.BackColor = System.Drawing.Color.DarkSlateBlue
    Label1.ForeColor = System.Drawing.Color.Gold
    Label1.BorderStyle = System.Web.UI.WebControls.BorderStyle.Inset
    
    ' Display the results in a Label Web Form server control.
    If UsageCount = 1 Then
        Label1.Text = "Web service has been utilized >" & UsageCount.ToString() & "< time."
    Else
        Label1.Text = "Web service has been utilized >" & UsageCount.ToString() & "< times."
    End If
End Sub
</script>

請參閱

概念

建置 XML Web Service 用戶端

其他資源

建立 XML Web Service 的用戶端

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.