WebService原理浅析

本文深入浅出地介绍了WebService的工作原理,包括其与编程语言类的对比、WSDL的作用和组成部分,以及如何通过HTTP+SOAP协议进行数据交互。通过示例详细解析了WSDL中的types、message、portType、binding和服务,帮助读者理解如何使用和调试WebService。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

WebService和编程语言中的类相似,它们都实现了一些功能,并且通过方法供给外部调用,不同的是WebService是部署在网络服务器上,而类在同一个进程空间里面。WebService部署在网络上,通过网络进行服务调用,只要遵循了访问协议,任何编程语言都可以访问服务,所以它是编程语言不相关的。

我们可以通过类文件知道一个类提供了哪些方法,那怎么知道WebService提供了哪些服务供外部调用呢?每一个WebService都有一个WSDL文件,WSDL全称Web Services Description Language(网络服务描述语言),WSDL有两个作用:

  1. 描述了WebService提供的服务,就像类里面的方法,包含名字、参数、返回值。
  2. 描述了访问服务的方法。

下面是一个WSDL的示例文件:

 
<?xml version="1.0" encoding="utf-8"?>

<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.7-b01  svn-revision#${svn.Last.Changed.Rev}. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.7-b01  svn-revision#${svn.Last.Changed.Rev}. -->
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://example/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example/" name="HelloWorldService">  
  <types> 
    <xsd:schema> 
      <xsd:import namespace="http://example/" schemaLocation="http://localhost:9090/HelloWorld?xsd=1"/> 
    </xsd:schema> 
  </types>  
  <message name="sayHelloWorld"> 
    <part name="parameters" element="tns:sayHelloWorld"/> 
  </message>  
  <message name="sayHelloWorldResponse"> 
    <part name="parameters" element="tns:sayHelloWorldResponse"/> 
  </message>  
  <portType name="HelloWorld"> 
    <operation name="sayHelloWorld"> 
      <input wsam:Action="http://example/HelloWorld/sayHelloWorldRequest" message="tns:sayHelloWorld"/>  
      <output wsam:Action="http://example/HelloWorld/sayHelloWorldResponse" message="tns:sayHelloWorldResponse"/> 
    </operation> 
  </portType>  
  <binding name="HelloWorldPortBinding" type="tns:HelloWorld"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>  
    <operation name="sayHelloWorld"> 
      <soap:operation soapAction=""/>  
      <input> 
        <soap:body use="literal"/> 
      </input>  
      <output> 
        <soap:body use=
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值