hjr-ASP.NET:Webservice

#分布式应用程序
有服务器有客户端互相数据交互的程序
#Webservice
使用xml数据格式,可以在多端进行数据交互,是一个规定的基于XML的通信标准
##服务器
新建一个Webservice项目,配置好之后返回xml数据。

添加新项->添加WEB服务,建好后其中

WebService.cs负责逻辑部分,WebService.asmx提供服务部分。将来引用WebService服务时将直接引用WebService.asmx文件来调用WebService服务.

WebService.cs新建服务

/*
   Web.Services.cs文件
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //如果使用设计的组件,请取消注释以下行 
        //InitializeComponent(); 
    }

    /// <summary>
    /// 方法上头的[WebMethod]是声明一个web服务方法,如果你想写个方法能让客户端调用并返回结果就必须在方法上头标注[WebMethod]
    /// 如果是只负责逻辑运算或私有方法,并不打算给客户端结果,只给类方法内部调用就无需声明[WebMethod]
    /// </summary>
    /// <param name="a"></param>
    /// <param name="b"></param>
    /// <returns>将运算结果转换成字符串返回</returns>
    [WebMethod]
    public string HelloWorld(int a, int b) {
        int result = a + b;
        return result.ToString();
    }    
}

再使用url,后缀为WebService.asmx访问,可以看到已经写好的服务列表,点击后可以访问服务查看返回的xml数据。
##客户端
通过url访问后接收到xml数据,再对该数据解析

##应用
比如某银行使用的技术就是Webservice写的服务,把可以共享的数据写到Webservice的服务里,并把url作为接口提供给商家,商家使用该接口访问xml数据并解析出来再进行应用。

以下是一个简单的 HTML 代码示例,可以用来制作类似于 iPhone 的网页: ```html <!DOCTYPE html> <html> <head> <title>iPhone 网页示例</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { background-color: #f2f2f2; font-family: Arial, Helvetica, sans-serif; } .container { margin: 20px auto; max-width: 400px; background-color: #fff; border-radius: 10px; padding: 20px; box-shadow: 0px 0px 10px rgba(0,0,0,0.2); } .header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; } .header img { height: 30px; } .navbar { display: flex; background-color: #eee; border-radius: 5px; overflow: hidden; margin-bottom: 20px; } .navbar a { display: block; padding: 10px; text-align: center; flex: 1; text-decoration: none; color: #555; font-weight: bold; } .navbar a.active { background-color: #007aff; color: #fff; } .content { text-align: center; margin-bottom: 20px; } .content img { max-width: 100%; height: auto; margin-bottom: 10px; } .footer { text-align: center; font-size: 12px; color: #aaa; } </style> </head> <body> <div class="container"> <div class="header"> <img src="https://i.imgur.com/6f8yvRP.png" alt="iPhone" /> <button>搜索</button> </div> <div class="navbar"> <a href="#" class="active">主页</a> <a href="#">新闻</a> <a href="#">社交</a> <a href="#">设置</a> </div> <div class="content"> <img src="https://i.imgur.com/4a74HJr.jpg" alt="iPhone" /> <h2>欢迎来到 iPhone 网页示例</h2> <p>这是一个简单的 HTML 示例,用于展示如何制作类似于 iPhone 的网页。</p> </div> <div class="footer"> <p>©2021 iPhone 网页示例</p> </div> </div> </body> </html> ``` 在浏览器中打开该 HTML 文件,即可看到类似于 iPhone 的网页效果。可以根据需要进行修改和调整。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

架构师小侯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值