Share via


How to: Create an ASP.NET Web Form Client 

Code Example

An ASP.NET Web Form that acts as a Web service client differs from other Web service clients in how the proxy class is referenced and how it is deployed. Specifically, public classes in assemblies, deployed into the \Bin directory under the Web application containing the Web Form, can be created from an ASP.NET Web Form. Therefore, if you create a Web service client proxy class, compile it into an assembly, and place it in the \Bin directory, the ASP.NET Web Form can create an instance of the proxy class.

To create a Web Form client for a Web service

  • Create a proxy for your Web service.

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

    For more information, see Creating an XML Web Service Proxy.

Compile the Web service proxy into an assembly, including the System.Xml.dll and System.Web.Services.dll assemblies and the proxy created in step 1.

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

Example

 <%@ Page Language="C#" %>
<asp:Label id="Label1" runat="server" />
<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" runat="server" />
<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>

See Also

Concepts

Building XML Web Service Clients

Other Resources

Creating Clients for XML Web Services