WebServices简单例子 - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
Apr 16

WebServices简单例子 不指定

tommyhu , 23:39 , ASP.NET , Comments(0) , Trackbacks(0) , Reads(5934) , Via Original Large | Medium | Small
1。编写HelloWorld.asmx
<%@ WebService Language="C#" Class="HelloWorld"%>

using System;
using System.Web.Services;

[WebService(Namespace="http://gloryview.com/webservices")]
public class HelloWorld: WebService
{
[WebMethod]
public String SayHelloWorld()
{
return "Hello World!";
}
}

2。调用命令行,输入:
disco /o:Test http://192.168.1.96/aspx/HelloWorld.asmx
/o:Test 存放到Test目录下,默认为当前目录

3。C:\Inetpub\wwwroot\aspx\Test>wsdl.exe /l:CS /n:TestServices /out:HelloWorld.cs HelloWorld.wsdl
/n: WebServices名字空间,给aspx客户端调用时引入的名字空间
/out:输出cs文件,然后编译成dll,给客户端调用

4。csc /t:library HelloWorld.cs
编译成HelloWorld.dll,存放在bin目录下。

5。编写Test.aspx
<%@ Page Language="C#" %>
<%@ import Namespace="yytest" %>
<script runat="server">

    void Button1_Click(object sender, EventArgs e) {
        HelloWorld myHelloWorld = new HelloWorld();
        String sReturn = myHelloWorld.SayHelloWorld();
        TextBox1.Text = sReturn;
    }

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
        </p>
        <p>
            <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
        </p>
        <!-- Insert content here -->
    </form>
</body>
</html>

拷贝Test.aspx和bin目录到客户端上,然后访问http://localhost/../Test.aspx
此时是调用服务器端的WebServices。
▲返回顶部
Last modified by tommyhu on2011/04/16 23:44

Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot