Procedura: Creare un client modulo Web ASP.NET

Code Example

Un Web Form ASP.NET che agisce come un client di servizio Web differisce dagli altri client di servizio Web nel modo in cui viene fatto riferimento alla classe proxy e nel modo in cui viene distribuito. Specificamente, classi pubbliche negli assembly, distribuite nella directory \Bin sotto l'applicazione Web che contiene il Web form, possono essere create da un Web form ASP.NET. Pertanto, se si crea una classe proxy client di servizio Web, la si compila in un assembly e la si posiziona nella directory \Bin, il Web Form ASP.NET può creare un'istanza della classe proxy.

Creare un client Web form per un servizio Web.

  • Creare un proxy client per un servizio Web.

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

    Per ulteriori informazioni, vedere Creazione di un proxy del servizio Web XML.

Compilare il proxy del servizio Web in un assembly, inclusi gli assembly System.Xml.dll e System.Web.Services.dll e il proxy creati nel passaggio 1.

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

Esempio

 <%@ 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>

Vedere anche

Concetti

Creazione di client dei servizi Web XML

Altre risorse

Creazione di client di servizi Web XML

Footer image

Copyright © 2007 Microsoft Corporation. Tutti i diritti riservati.