Archive for c#

.Net Assemblies

References
Using Assemblies

Easy .Net Web Service

Create a hello world web service

  • Create a directory: c:\HelloServices
  • Create an asmx file: HelloService.asmx
  •  
    <%@ WebService Language="C#"
      Class="HelloService"%>
     
    using System;
    using System.Web.Services;
    using System.Xml.Serialization;
     
    [WebService(
      Namespace="http://localhost/HelloServices/")]
    public class HelloService : WebService
    {
        [WebMethod]
        public string SayHello()
        {
            return "Hello World!";
        }
    }
  • Create an IIS virtual directory: HelloServices and point to c:\HelloServices
  • Point browser to http://localhost/HelloServices/HelloService.asmx
  • Create an aspx web page to consume HelloService

  • Create a directory: c:\HelloServiceWeb
  • Create a subdirectory c:\HelloServiceWeb\bin
  • Generate HelloService proxy
    • wsdl http://localhost/HelloServices/HelloService.asmx
    • csc /t:library HelloService.cs
  • Copy generated HelloService.dll to bin directory
  • Create an aspx page: HelloServiceWeb.aspx
  • <%@ Page Language="C#" %>
    <script runat=server>
      void runService_Click(
        Object sender, EventArgs e)
      {
        HelloService hs = new HelloService();
        Label1.Text = hs.SayHello();
      }
    </script>
    <html>
      <body>
    <form id="Form1" runat=server>
          <asp:Label id="Label1"
            runat="server">Label</asp:Label>
     
          <asp:Button id="runService"
            onclick="runService_Click"
            runat="server"
            Text="Hello"/>
        </form>
     
      </body>
    </html>
  • Create an IIS virtual directory: HelloServiceWeb and point to c:\HelloServiceWeb
  • Point browser to http://localhost/HelloServiceWeb/HelloServiceWeb.aspx
  • Spring.Net Object Definition

     
    <object name="SingletonObject"
      type="Test.Singleton, Test"
      factory-method="CreateInstance">
    <property name="Greetings" value="Hello"/>
    <property name="ExpiryDate" value="4/16/2010"/>
    </object>

    XSD.exe

    • Generate classes from XSD file
      • xsd.exe /c MySchema.xsd
    • Generate XSD file from an assembly
      • xsd.exe MyAssembly.dll /t:TypeName