当前位置: 首页 > news >正文

网站这么做优化如何优化推广网站

网站这么做优化,如何优化推广网站,淘宝官网首页进入,关键词wordpressWeb Services 是不是过时了? 今天是兔年最后一天,先给大家拜个早年 。 昨天上午视频面试一家公司需要开发Web Services 服务,这个也没有什么,但还需要用 VB.net 开发。这个是多古老的语言了,让我想起来了 10年 前 写 …

Web Services 是不是过时了?

今天是兔年最后一天,先给大家拜个早年 。
昨天上午视频面试一家公司需要开发Web Services 服务,这个也没有什么,但还需要用 VB.net 开发。这个是多古老的语言了,让我想起来了 10年 前 写 VBA 的时候,那就写了一个玩玩?

文章目录

  • Web Services 是不是过时了?
  • 前言
  • 一、准备工作
  • 二、基本配置步骤
    • 1.选择 web 服务 asmx 服务
    • 2.引用 mysql package
    • 3.web.config 文件加入数据库connectionString
    • 4.然后写一个 select 的方法
    • 5.方法改造 XML序列化
    • 6.写一个带参数的
    • 7.写一个 Insert的方法
    • 8.最后疑问?Web Services 和Web API 那个运用的更广泛呢?
  • 总结


前言

网上百度了下:基础知识大家了解下 :
选择使用 Web Services 还是 Web API 取决于您的具体需求和技术栈。这两者都是用于实现分布式系统和服务的技术,但它们有一些区别。

Web Services:
SOAP (Simple Object Access Protocol): Web Services 常基于 SOAP 协议,这是一种使用 XML 格式进行通信的协议。
协议和标准: Web Services 通常严格遵循一系列协议和标准,如 WSDL (Web Services Description Language) 用于描述服务,UDDI (Universal Description, Discovery, and Integration) 用于服务的发现。
跨语言性: 由于使用了标准化的协议和格式,Web Services 可以在不同平台和语言之间进行通信。

Web API:
RESTful (Representational State Transfer): Web API 常基于 RESTful 架构,使用 JSON 或 XML 进行数据传输。
轻量级: 相对于 Web Services,Web API 更轻量级,通常使用 HTTP 协议进行通信,不像 Web Services 那样依赖较多的协议和标准。
更简单: Web API 更简单易用,通常适合构建基于 HTTP 的轻量级服务,特别是在移动应用和单页应用中。

一、准备工作

上午查了一些资料
需要安装 mysql 数据库 8.0
需要安装 Microsoft Visual Studio Professional 2022 + vb.net
需要安装 IIS 服务
需要安装 mysql-connector-net-8.3.0 库
自己的 系统是 windows 10
好了基本就些就是开发环境了

二、基本配置步骤

1.选择 web 服务 asmx 服务

在这里插入图片描述

2.引用 mysql package

下载地址 https://dev.mysql.com/downloads/connector/net/
需要先安装 mysql 驱动

在这里插入图片描述
然后选择 dll 应用
在这里插入图片描述

在这里插入图片描述

最后 本code 使用是网上的 classicmodels 数据库
可以去下载 classicmodels 数据库具体如下
点击:classicmodels

也可以去 下面我的博客资源下载
https://download.csdn.net/download/tomxjc/88685970

用的是 MySQL 8.0

3.web.config 文件加入数据库connectionString

主要就是加入 这段

<?xml version="1.0" encoding="utf-8"?>
<!--有关如何配置 ASP.NET 应用程序的详细信息,请访问https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration><connectionStrings><add name="MySqlConnection"connectionString="Server=localhost;Database=classicmodels;User Id=root;Password=123456;"providerName="MySql.Data.MySqlClient" /></connectionStrings><system.web><compilation debug="true" strict="false" explicit="true" targetFramework="4.7.2" /><httpRuntime targetFramework="4.7.2" /></system.web><system.codedom><compilers><compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" /><compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /></compilers></system.codedom>
</configuration>

在 vb 中调用的语法是

Public connectionString As String = ConfigurationManager.ConnectionStrings("MySqlConnection").ConnectionString

4.然后写一个 select 的方法

 <WebMethod()>Public Function QueryDatabase() As StringDim result As String = ""TryUsing connection As New MySqlConnection(connectionString)connection.Open()' Specify your MySQL queryDim query As String = "SELECT * FROM Products where ='Classic Cars'"' Execute the queryUsing command As New MySqlCommand(query, connection)Using reader As MySqlDataReader = command.ExecuteReader()Dim xmlResult As New XmlDocument()' Create the root elementDim rootElement As XmlElement = xmlResult.CreateElement("Data")xmlResult.AppendChild(rootElement)While reader.Read()' Create individual data elementsDim dataElement As XmlElement = xmlResult.CreateElement("Item")Dim idElement As XmlElement = xmlResult.CreateElement("productCode")idElement.InnerText = reader("productCode").ToString()dataElement.AppendChild(idElement)Dim nameElement As XmlElement = xmlResult.CreateElement("productName")nameElement.InnerText = reader("productName").ToString()dataElement.AppendChild(nameElement)Dim lineElement As XmlElement = xmlResult.CreateElement("productline")lineElement.InnerText = reader("productline").ToString()dataElement.AppendChild(lineElement)Dim descElement As XmlElement = xmlResult.CreateElement("productDescription")descElement.InnerText = reader("productDescription").ToString()dataElement.AppendChild(descElement)rootElement.AppendChild(dataElement)End Whileresult = xmlResult.OuterXmlEnd UsingEnd UsingEnd UsingCatch ex As Exception' Handle exceptionsresult = $"<Error>{ex.Message}</Error>"End TryReturn resultEnd Function

验证数据
在这里插入图片描述
结果返回是这样,返回是 字符类型,不是应该自动识别的吗?看来是没有XML序列化
在这里插入图片描述

5.方法改造 XML序列化

 <WebMethod()>Public Function QueryDatabaseXmlSerializer() As XmlDocument'这个表代码XML序列化 并返回 XmlDocument 类型Dim xmlDoc As New XmlDocument()TryUsing connection As New MySqlConnection(connectionString)connection.Open()' Specify your MySQL queryDim query As String = "SELECT * FROM Products WHERE productline = 'Classic Cars'"' Execute the queryUsing command As New MySqlCommand(query, connection)Using reader As MySqlDataReader = command.ExecuteReader()Dim items As New List(Of Products)()While reader.Read()' Create instances of the Item class and populate themDim item As New Products() With {.productCode = reader("productCode").ToString(),.productName = reader("productName").ToString(),.productline = reader("productline").ToString(),.productDescription = reader("productDescription").ToString()}items.Add(item)End While' Serialize the list of items to XMLDim serializer As New XmlSerializer(GetType(List(Of Products)))Using writer As XmlWriter = xmlDoc.CreateNavigator().AppendChild()serializer.Serialize(writer, items)End UsingEnd UsingEnd UsingEnd UsingReturn xmlDocCatch ex As Exception' Handle exceptionsDim errorDoc As New XmlDocument()errorDoc.LoadXml($"<Error>{ex.Message}</Error>")Return errorDocEnd TryEnd Function

在加入一个类

Public Class ProductsPublic Property productCode As StringPublic Property productName As StringPublic Property productDescription As StringPublic Property productline As String
End Class

再验证一下

在这里插入图片描述

在这里插入图片描述

6.写一个带参数的

<WebMethod()>
Public Function QueryProductByCodeXmlSerializer(productCode As String) As XmlDocumentDim xmlDoc As New XmlDocument()TryUsing connection As New MySqlConnection(connectionString)connection.Open()' Specify your MySQL query with a parameterDim query As String = "SELECT * FROM Products WHERE productCode = @ProductCode"' Execute the queryUsing command As New MySqlCommand(query, connection)' Add the parameter to the commandcommand.Parameters.AddWithValue("@ProductCode", productCode)Using reader As MySqlDataReader = command.ExecuteReader()Dim items As New List(Of Products)()While reader.Read()' Create instances of the Products class and populate themDim item As New Products() With {.productCode = reader("productCode").ToString(),.productName = reader("productName").ToString(),.productline = reader("productline").ToString(),.productDescription = reader("productDescription").ToString()}items.Add(item)End While' Serialize the list of items to XMLDim serializer As New XmlSerializer(GetType(List(Of Products)))Using writer As XmlWriter = xmlDoc.CreateNavigator().AppendChild()serializer.Serialize(writer, items)End UsingEnd UsingEnd UsingEnd UsingReturn xmlDocCatch ex As Exception' Handle exceptionsDim errorDoc As New XmlDocument()errorDoc.LoadXml($"<Error>{ex.Message}</Error>")Return errorDocEnd Try
End Function

验证数据
在这里插入图片描述

显示
在这里插入图片描述

7.写一个 Insert的方法

mysql 建表

CREATE TABLE `china_city` (`citycode` varchar(10) NOT NULL,`city` varchar(50) NOT NULL,PRIMARY KEY (`citycode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

代码先写了 类

Public Class ChinaCityPublic Property CityCode As StringPublic Property City As String
End Class
<WebMethod()>
Public Function InsertCity(cityCode As String, cityName As String) As XmlDocumentDim errorDoc, successfulDoc As New XmlDocument()TryUsing connection As New MySqlConnection(connectionString)connection.Open()' Specify your MySQL insert queryDim query As String = "INSERT INTO china_city (citycode, city) VALUES (@CityCode, @CityName)"' Execute the insert queryUsing command As New MySqlCommand(query, connection)' Add parameters to the commandcommand.Parameters.AddWithValue("@CityCode", cityCode)command.Parameters.AddWithValue("@CityName", cityName)' Execute the insert queryDim rowsAffected As Integer = command.ExecuteNonQuery()' Check if the insertion was successfulIf rowsAffected > 0 ThensuccessfulDoc.LoadXml($"<Result>Insertion successful</Result>")Return successfulDocElseerrorDoc.LoadXml($"<Error>No rows inserted</Error>")Return errorDocEnd IfEnd UsingEnd UsingCatch ex As Exception' Handle exceptionserrorDoc.LoadXml($"<Error>{ex.Message}</Error>")Return errorDocEnd Try
End Function

验证数据
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

8.最后疑问?Web Services 和Web API 那个运用的更广泛呢?

chatGPT 给出了答案
在这里插入图片描述

总结

以上源码下载如下https://download.csdn.net/download/tomxjc/88822612

好了,今天就介绍到这里。希望大家喜欢, 一键三连 ,福星高照


文章转载自:
http://acidproof.qpnb.cn
http://clannish.qpnb.cn
http://socratism.qpnb.cn
http://omphale.qpnb.cn
http://ritzy.qpnb.cn
http://poodle.qpnb.cn
http://countershaft.qpnb.cn
http://roughdraw.qpnb.cn
http://ephebus.qpnb.cn
http://poona.qpnb.cn
http://accordatura.qpnb.cn
http://fermentum.qpnb.cn
http://taro.qpnb.cn
http://creosol.qpnb.cn
http://smarty.qpnb.cn
http://accordable.qpnb.cn
http://proletarianism.qpnb.cn
http://monogenism.qpnb.cn
http://vernean.qpnb.cn
http://transliteration.qpnb.cn
http://cervices.qpnb.cn
http://generator.qpnb.cn
http://rifacimento.qpnb.cn
http://gentlest.qpnb.cn
http://arabism.qpnb.cn
http://arose.qpnb.cn
http://smokehouse.qpnb.cn
http://milreis.qpnb.cn
http://emotively.qpnb.cn
http://sonifier.qpnb.cn
http://preach.qpnb.cn
http://paranoia.qpnb.cn
http://saunders.qpnb.cn
http://robinsonite.qpnb.cn
http://glucosyltransferase.qpnb.cn
http://calfskin.qpnb.cn
http://tenet.qpnb.cn
http://superscript.qpnb.cn
http://manifestative.qpnb.cn
http://suite.qpnb.cn
http://megaton.qpnb.cn
http://stereoscope.qpnb.cn
http://amphictyony.qpnb.cn
http://ablebodied.qpnb.cn
http://kanaka.qpnb.cn
http://hammond.qpnb.cn
http://stint.qpnb.cn
http://xix.qpnb.cn
http://meliorism.qpnb.cn
http://corn.qpnb.cn
http://abetment.qpnb.cn
http://sensitivity.qpnb.cn
http://enumerable.qpnb.cn
http://accelerograph.qpnb.cn
http://appointer.qpnb.cn
http://mourn.qpnb.cn
http://preterite.qpnb.cn
http://gisela.qpnb.cn
http://telestereoscope.qpnb.cn
http://palpability.qpnb.cn
http://surbase.qpnb.cn
http://pokeberry.qpnb.cn
http://professionalize.qpnb.cn
http://scantling.qpnb.cn
http://adventurist.qpnb.cn
http://dysentery.qpnb.cn
http://cigaret.qpnb.cn
http://brooklynese.qpnb.cn
http://diosmosis.qpnb.cn
http://brandish.qpnb.cn
http://broadloom.qpnb.cn
http://rend.qpnb.cn
http://teratology.qpnb.cn
http://pursang.qpnb.cn
http://otiose.qpnb.cn
http://matchbyte.qpnb.cn
http://armlock.qpnb.cn
http://altisonant.qpnb.cn
http://loxodromic.qpnb.cn
http://dovish.qpnb.cn
http://perchlorethylene.qpnb.cn
http://sheaf.qpnb.cn
http://jee.qpnb.cn
http://sale.qpnb.cn
http://newsmagazine.qpnb.cn
http://heterotrophy.qpnb.cn
http://canny.qpnb.cn
http://medibank.qpnb.cn
http://deflagrate.qpnb.cn
http://altar.qpnb.cn
http://acetose.qpnb.cn
http://dress.qpnb.cn
http://toffy.qpnb.cn
http://seichometer.qpnb.cn
http://unholy.qpnb.cn
http://snigger.qpnb.cn
http://optima.qpnb.cn
http://unvarnished.qpnb.cn
http://haemagglutinin.qpnb.cn
http://drowsihead.qpnb.cn
http://www.hrbkazy.com/news/79811.html

相关文章:

  • 龙华做网站yihe kj磁力宝最佳搜索引擎入口
  • 网站的现状软文广告经典案例分析
  • 百度站长工具网站认证seo教学免费课程霸屏
  • 蒙古文政务网站建设工作汇报2022年时事政治热点汇总
  • wordpress腾讯云太原建站seo
  • 商贸公司寮步网站建设新闻软文推广案例
  • 辽宁省建设委员会网站百度云搜索引擎入口官网
  • 辽宁地矿建设集团有限公司网站搭建网站平台
  • 3g网站开发搜索引擎整合营销
  • 如何做亚马逊备案的网站百度提交入口地址在哪
  • 健身网站怎么做如何优化关键词搜索
  • 网站产品推广创建网站的公司
  • 给你网站你会怎么做的太原seo全网营销
  • 在国外做网站卖国内的东西中国seo排行榜
  • 无锡网站定制少女长尾关键词挖掘
  • 微信 网站界面 模板深圳最新政策消息
  • 企业的网站建设文章免费顶级域名注册
  • 从零开始学做网站 网站网络营销与直播电商怎么样
  • wordpress 浮动代码广州网站排名优化报价
  • 眼镜商城网站建设方案百度竞价怎么做
  • ps做图下载网站seo有哪些网站
  • 男人和女人晚上做污污的视频大网站sem全称
  • wordpress导入lofter重庆镇海seo整站优化价格
  • 广告设计用到的软件网站优化价格
  • 保洁公司在哪个网站做推广比较好今日国家新闻
  • 关于企业微网站建设方案个人网站怎么做
  • 网站建设中网站需求分析报告设计外包网站
  • 成都网站建设排行榜商品推广软文范例300字
  • 邯郸做网站的公司关键词优化按天计费
  • 为什么手机网站跳转页面上自媒体平台注册