restful soap

Welcome to the Web Services Interview Questions with detailed answers. Recently I have written a lot about web services. How we can create SOAP and RESTful web services in Java.

欢迎来到提供详细答案的Web服务面试问题。 最近,我写了很多关于Web服务的文章。 我们如何用Java创建SOAP和RESTful Web服务。

Web服务面试问题 (Web Services Interview Questions)

Here I am providing you a list of web services interview questions to help you in interview. First of all there are generic questions for web services concept since it’s not technology or language specific and then we have java web services interview questions.

在这里,我向您提供Web服务面试问题列表,以帮助您进行面试。 首先,由于Web服务概念不是特定于技术或语言的,因此存在Web服务概念的一般性问题,然后是Java Web Service面试问题

  1. What is a Web Service?什么是Web服务?
  2. What are the advantages of Web Services?Web服务的优点是什么?
  3. What are different types of Web Services?有哪些不同类型的Web服务?
  4. What is SOAP?什么是SOAP?
  5. What are advantages of SOAP Web Services?SOAP Web服务的优点是什么?
  6. What are disadvantages of SOAP Web Services?SOAP Web服务的缺点是什么?
  7. What is WSDL?什么是WSDL?
  8. What are different components of WSDL?WSDL有哪些不同的组件?
  9. What is UDDI?什么是UDDI?
  10. What is difference between Top Down and Bottom Up approach in SOAP Web Services?SOAP Web Services中的“自上而下”和“自下而上”方法有什么区别?
  11. What is REST Web Services?什么是REST Web服务?
  12. What are advantages of REST web services?REST Web服务的优点是什么?
  13. What are disadvantages of REST web services?REST Web服务的缺点是什么?
  14. What is a Resource in Restful web services?Restful Web服务中的资源是什么?
  15. What are different HTTP Methods supported in Restful Web Services?Restful Web Services支持哪些不同的HTTP方法?
  16. Compare SOAP and REST web services?比较SOAP和REST Web服务?
  17. What are different ways to test web services?有什么不同的方法来测试Web服务?
  18. Can we maintain user session in web services?我们可以在Web服务中维护用户会话吗?
  19. What is difference between SOA and Web Services?SOA和Web服务之间有什么区别?
  20. What is the use of Accept and Content-Type Headers in HTTP Request?HTTP请求中Accept和Content-Type标头的用途是什么?
  21. How would you choose between SOAP and REST web services?您如何在SOAP和REST Web服务之间进行选择?
  22. What is JAX-WS API?什么是JAX-WS API?
  23. Name some frameworks in Java to implement SOAP web services?用Java命名一些框架来实现SOAP Web服务吗?
  24. Name important annotations used in JAX-WS API?命名JAX-WS API中使用的重要注释?
  25. What is use of javax.xml.ws.Endpoint class?javax.xml.ws.Endpoint类的用途是什么?
  26. What is the difference between RPC Style and Document Style SOAP web Services?RPC样式和文档样式SOAP Web服务之间有什么区别?
  27. How to get WSDL file of a SOAP web service?如何获取SOAP Web服务的WSDL文件?
  28. What is sun-jaxws.xml file?什么是sun-jaxws.xml文件?
  29. What is JAX-RS API?什么是JAX-RS API?
  30. Name some implementations of JAX-RS API?列举一些JAX-RS API的实现?
  31. What is wsimport utility?什么是wsimport实用程序?
  32. Name important annotations used in JAX-RS API?命名JAX-RS API中使用的重要注释?
  33. What is the use of @XmlRootElement annotation?@XmlRootElement注释的用途是什么?
  34. How to set different status code in HTTP response?如何在HTTP响应中设置不同的状态码?
  1. 什么是Web服务? (What is a Web Service?)

    Web Services work on client-server model where client applications can access web services over the network. Web services provide endpoint URLs and expose methods that can be accessed over network through client programs written in java, shell script or any other different technologies.
    Web services are stateless and doesn’t maintain user session like web applications.

    Web服务在客户端-服务器模型上工作,其中客户端应用程序可以通过网络访问Web服务。 Web服务提供端点URL并公开方法,这些方法可以通过用Java,Shell脚本或任何其他不同技术编写的客户端程序通过网络进行访问。
    Web服务是无状态的,不会像Web应用程序那样维护用户会话。

  2. Web服务的优点是什么? (What are the advantages of Web Services?)

    Some of the advantages of web services are:

    • Interoperability: Web services are accessible over network and runs on HTTP/SOAP protocol and uses XML/JSON to transport data, hence it can be developed in any programming language. Web service can be written in java programming and client can be PHP and vice versa.
    • Reusability: One web service can be used by many client applications at the same time.
    • Loose Coupling: Web services client code is totally independent with server code, so we have achieved loose coupling in our application.
    • Easy to deploy and integrate, just like web applications.
    • Multiple service versions can be running at same time.

    Web服务的一些优点是:

    • 互操作性:Web服务可通过网络访问,并以HTTP / SOAP协议运行,并使用XML / JSON传输数据,因此可以使用任何编程语言进行开发。 Web服务可以用Java编程编写,客户端可以是PHP,反之亦然。
    • 可重用性:一个Web服务可以同时被许多客户端应用程序使用。
    • 松散耦合:Web服务客户端代码与服务器代码完全独立,因此我们在应用程序中实现了松散耦合。
    • 就像Web应用程序一样,易于部署和集成。
    • 可以同时运行多个服务版本。
  3. 有哪些不同类型的Web服务? (What are different types of Web Services?)

    There are two types of web services:

    1. SOAP Web Services: Runs on SOAP protocol and uses XML technology for sending data.
    2. Restful Web Services: It’s an architectural style and runs on HTTP/HTTPS protocol almost all the time. REST is a stateless client-server architecture where web services are resources and can be identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful web services.

    Web服务有两种类型:

    1. SOAP Web服务:在SOAP协议上运行,并使用XML技术发送数据。
    2. 宁静的Web服务:这是一种体系结构样式,几乎始终在HTTP / HTTPS协议上运行。 REST是一种无状态的客户端-服务器体系结构,其中Web服务是资源,可以通过其URI进行标识。 客户端应用程序可以使用HTTP GET / POST方法来调用Restful Web服务。
  4. 什么是SOAP? (What is SOAP?)

    SOAP stands for Simple Object Access Protocol. SOAP is an XML based industry standard protocol for designing and developing web services. Since it’s XML based, it’s platform and language independent. So our server can be based on JAVA and client can be on .NET, PHP etc. and vice versa.

    SOAP代表简单对象访问协议。 SOAP是用于设计和开发Web服务的基于XML的行业标准协议。 由于它基于XML,因此与平台和语言无关。 因此,我们的服务器可以基于JAVA,客户端可以基于.NET,PHP等,反之亦然。

  5. SOAP Web服务的优点是什么? (What are advantages of SOAP Web Services?)

    SOAP web services have all the advantages that web services has, some of the additional advantages are:

    • WSDL document provides contract and technical details of the web services for client applications without exposing the underlying implementation technologies.
    • SOAP uses XML data for payload as well as contract, so it can be easily read by any technology.
    • SOAP protocol is universally accepted, so it’s an industry standard approach with many easily available open source implementations.

    SOAP Web服务具有Web服务所具有的所有优点,其中一些其他优点是:

    • WSDL文档为客户端应用程序提供了Web服务的合同和技术细节,而没有暴露底层的实现技术。
    • SOAP将XML数据用于有效负载和合同,因此任何技术都可以轻松读取它。
    • SOAP协议已被普遍接受,因此它是一种行业标准的方法,具有许多易于使用的开源实现。
  6. SOAP Web服务的缺点是什么? (What are disadvantages of SOAP Web Services?)

    Some of the disadvantages of SOAP protocol are:

    • Only XML can be used, JSON and other lightweight formats are not supported.
    • SOAP is based on the contract, so there is a tight coupling between client and server applications.
    • SOAP is slow because payload is large for a simple string message, since it uses XML format.
    • Anytime there is change in the server side contract, client stub classes need to be generated again.
    • Can’t be tested easily in browser

    SOAP协议的一些缺点是:

    • 只能使用XML,不支持JSON和其他轻量级格式。
    • SOAP基于合同,因此客户端和服务器应用程序之间紧密耦合。
    • SOAP速度很慢,因为有效载荷对于简单的字符串消息而言很大,因为它使用XML格式。
    • 只要服务器端合同发生变化,就需要再次生成客户端存根类。
    • 无法在浏览器中轻松测试
  7. 什么是WSDL? (What is WSDL?)

    WSDL stands for Web Service Description Language. WSDL is an XML based document that provides technical details about the web service. Some of the useful information in WSDL document are: method name, port types, service end point, binding, method parameters etc.

    WSDL代表Web服务描述语言。 WSDL是基于XML的文档,提供有关Web服务的技术详细信息。 WSDL文档中的一些有用信息包括:方法名称,端口类型,服务端点,绑定,方法参数等。

  8. WSDL有哪些不同的组件? (What are different components of WSDL?)

    Some of the different tags in WSDL xml are:

    • xsd:import namespace and schemaLocation: provides WSDL URL and unique namespace for web service.
    • message: for method arguments
    • part: for method argument name and type
    • portType: service name, there can be multiple services in a wsdl document.
    • operation: contains method name
    • soap:address for endpoint URL.

    WSDL xml中的一些不同标签是:

    • xsd:import名称空间和schemaLocation:为Web服务提供WSDL URL和唯一名称空间。
    • 消息:用于方法参数
    • 部分:用于方法参数名称和类型
    • portType:服务名称,wsdl文档中可以有多个服务。
    • 操作:包含方法名称
    • soap:端点URL的地址。
  9. 什么是UDDI? (What is UDDI?)

    UDDI is acronym for Universal Description, Discovery and Integration. UDDI is a directory of web services where client applications can lookup for web services. Web Services can register to the UDDI server and make them available to client applications.

    UDDI是通用描述,发现和集成的缩写。 UDDI是Web服务的目录,客户端应用程序可以在其中查找Web服务。 Web服务可以注册到UDDI服务器,并使它们可用于客户端应用程序。

  10. SOAP Web Services中的“自上而下”和“自下而上”方法有什么区别? (What is difference between Top Down and Bottom Up approach in SOAP Web Services?)

    In Top Down approach first WSDL document is created to establish the contract between web service and client and then code is written, it’s also termed as contract first approach. This is hard to implement because classes need to be written to confirm the contract established in WSDL. Benefit of this approach is that both client and server code can be written in parallel.

    In Bottom Up approach, first web service code is written and then WSDL is generated. It’s also termed as contract last approach. This approach is easy to implement because WSDL is generated based on code. In this approach client code have to wait for WSDL from server side to start their work.

    在自顶向下方法中,首先创建WSDL文档以建立Web服务与客户端之间的合同,然后编写代码,也称为合同优先方法。 这很难实现,因为需要编写类来确认WSDL中建立的合同。 这种方法的好处是客户端和服务器代码都可以并行编写。

    在自下而上的方法中,首先编写Web服务代码,然后生成WSDL。 它也被称为“最后合同”方法。 这种方法易于实现,因为WSDL是基于代码生成的。 在这种方法中,客户端代码必须等待服务器端的WSDL开始工作。

  11. 什么是REST Web服务? (What is REST Web Services?)

    REST is the acronym for REpresentational State Transfer. REST is an architectural style for developing applications that can be accessed over the network. REST architectural style was brought in light by Roy Fielding in his doctoral thesis in 2000.

    REST is a stateless client-server architecture where web services are resources and can be identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful web services. REST doesn’t specify any specific protocol to use, but in almost all cases it’s used over HTTP/HTTPS. When compared to SOAP web services, these are lightweight and doesn’t follow any standard. We can use XML, JSON, text or any other type of data for request and response.

    REST是代表状态转移的首字母缩写。 REST是一种体系结构样式,用于开发可通过网络访问的应用程序。 REST建筑风格是由Roy Fielding在2000年的博士论文中提出的。

    REST是一种无状态的客户端-服务器体系结构,其中Web服务是资源,可以通过其URI进行标识。 客户端应用程序可以使用HTTP GET / POST方法来调用Restful Web服务。 REST没有指定要使用的任何特定协议,但是在几乎所有情况下,它都是通过HTTP / HTTPS使用的。 与SOAP Web服务相比,它们是轻量级的,不遵循任何标准。 我们可以使用XML,JSON,文本或任何其他类型的数据进行请求和响应。

  12. REST Web服务的优点是什么? (What are advantages of REST web services?)

    Some of the advantages of REST web services are:

    • Learning curve is easy since it works on HTTP protocol
    • Supports multiple technologies for data transfer such as text, xml, json, image etc.
    • No contract defined between server and client, so loosely coupled implementation.
    • REST is a lightweight protocol
    • REST methods can be tested easily over browser.

    REST Web服务的一些优点是:

    • 学习曲线很容易,因为它适用于HTTP协议
    • 支持多种数据传输技术,例如文本,xml,json,图像等。
    • 服务器与客户端之间未定义合同,因此实现松散耦合。
    • REST是一种轻量级协议
    • REST方法可以通过浏览器轻松测试。
  13. REST Web服务的缺点是什么? (What are disadvantages of REST web services?)

    Some of the disadvantages of REST are:

    • Since there is no contract defined between service and client, it has to be communicated through other means such as documentation or emails.
    • Since it works on HTTP, there can’t be asynchronous calls.
    • Sessions can’t be maintained.

    REST的一些缺点是:

    • 由于服务与客户端之间未定义合同,因此必须通过其他方式(例如文档或电子邮件)进行通信。
    • 由于它可以在HTTP上运行,因此不能进行异步调用。
    • 会话无法维护。
  14. Restful Web服务中的资源是什么? (What is a Resource in Restful web services?)

    Resource is the fundamental concept of Restful architecture. A resource is an object with a type, relationship with other resources and methods that operate on it. Resources are identified with their URI, HTTP methods they support and request/response data type and format of data.

    资源是Restful体系结构的基本概念。 资源是具有类型,与其他资源的关系以及对其进行操作的方法的对象。 资源通过其URI,它们支持的HTTP方法以及请求/响应数据类型和数据格式来标识。

  15. Restful Web Services支持哪些不同的HTTP方法? (What are different HTTP Methods supported in Restful Web Services?)

    Restful web services supported HTTP methods are – GET, POST, PUT, DELETE and HEAD.

    静态Web服务支持的HTTP方法是– GET,POST,PUT,DELETE和HEAD。

  16. 比较SOAP和REST Web服务? (Compare SOAP and REST web services?)

    .tg {border-collapse:collapse;border-spacing:0;border-color:#999;} .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#444;background-color:#F7FDFA;} .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#fff;background-color:#26ADE4;} .tg .tg-baqh{text-align:center;vertical-align:top} .tg .tg-6k2t{background-color:#D2E4FC;vertical-align:top} .tg .tg-yw4l{vertical-align:top}

    SOAP REST
    SOAP is a standard protocol for creating web services. REST is an architectural style to create web services.
    SOAP is acronym for Simple Object Access Protocol. REST is acronym for REpresentational State Transfer.
    SOAP uses WSDL to expose supported methods and technical details. REST exposes methods through URIs, there are no technical details.
    SOAP web services and client programs are bind with WSDL contract REST doesn’t have any contract defined between server and client
    SOAP web services and client are tightly coupled with contract. REST web services are loosely coupled.
    SOAP learning curve is hard, requires us to learn about WSDL generation, client stubs creation etc. REST learning curve is simple, POJO classes can be generated easily and works on simple HTTP methods.
    SOAP supports XML data format only REST supports any data type such as XML, JSON, image etc.
    SOAP web services are hard to maintain, any change in WSDL contract requires us to create client stubs again and then make changes to client code. REST web services are easy to maintain when compared to SOAP, a new method can be added without any change at client side for existing resources.
    SOAP web services can be tested through programs or software such as Soap UI. REST can be easily tested through CURL command, Browsers and extensions such as Chrome Postman.

    .tg {border-collapse:collapse;border-spacing:0;border-color:#999;} .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#444;background-color:#F7FDFA;} .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#fff;background-color:#26ADE4;} .tg .tg-baqh{text-align:center;vertical-align:top} .tg .tg-6k2t{background-color:#D2E4FC;vertical-align:top} .tg .tg-yw4l{vertical-align:top}

    肥皂 休息
    SOAP是用于创建Web服务的标准协议。 REST是用于创建Web服务的体系结构样式。
    SOAP是简单对象访问协议的缩写。 REST是代表状态转移的缩写。
    SOAP使用WSDL公开支持的方法和技术细节。 REST通过URI公开方法,没有技术细节。
    SOAP Web服务和客户端程序与WSDL合同绑定 REST在服务器和客户端之间没有定义任何合同
    SOAP Web服务和客户端与合同紧密结合。 REST Web服务是松散耦合的。
    SOAP学习难度很大,需要我们学习WSDL的生成,客户端存根的创建等。 REST学习曲线很简单,可以轻松生成POJO类,并且可以在简单的HTTP方法上工作。
    SOAP仅支持XML数据格式 REST支持任何数据类型,例如XML,JSON,图像等。
    SOAP Web服务很难维护,WSDL合同中的任何更改都要求我们再次创建客户端存根,然后对客户端代码进行更改。 与SOAP相比,REST Web服务易于维护,可以在客户端不增加现有资源的情况下添加新方法。
    SOAP Web服务可以通过程序或软件(例如Soap UI)进行测试。 可以通过CURL命令,浏览器和扩展程序(例如Chrome Postman)轻松测试REST。
  17. 有什么不同的方法来测试Web服务? (What are different ways to test web services?)

    SOAP web services can be tested programmatically by generating client stubs from WSDL or through software such as Soap UI.

    REST web services can be tested easily with program, curl commands and through browser extensions. Resources supporting GET method can be tested with browser itself, without any program.

    通过从WSDL生成客户端存根或通过诸如Soap UI之类的软件,可以以编程方式测试SOAP Web服务。

    可以使用程序,curl命令和浏览器扩展轻松测试REST Web服务。 支持GET方法的资源可以使用浏览器本身进行测试,而无需任何程序。

  18. 我们可以在Web服务中维护用户会话吗? (Can we maintain user session in web services?)

    Web services are stateless so we can’t maintain user sessions in web services.

    Web服务是无状态的,因此我们无法在Web服务中维护用户会话。

  19. SOA和Web服务之间有什么区别? (What is difference between SOA and Web Services?)

    Service Oriented Architecture (SOA) is an architectural pattern where applications are designed in terms of services that can be accessed through communication protocol over network. SOA is a design pattern and doesn’t go into implementation.

    Web Services can be thought of as Services in SOAP architecture and providing means to implement SOA pattern.

    面向服务的体系结构(SOA)是一种体系结构模式,其中根据可以通过网络上的通信协议访问的服务来设计应用程序。 SOA是一种设计模式,不会付诸实施。

    可以将Web服务视为SOAP体系结构中的服务,并提供实现SOA模式的手段。

  20. HTTP请求中Accept和Content-Type标头的用途是什么? (What is the use of Accept and Content-Type Headers in HTTP Request?)

    These are important headers in Restful web services. Accept headers tells web service what kind of response client is accepting, so if a web service is capable of sending response in XML and JSON format and client sends Accept header as “application/xml” then XML response will be sent. For Accept header “application/json”, server will send the JSON response.

    Content-Type header is used to tell server what is the format of data being sent in the request. If Content-Type header is “application/xml” then server will try to parse it as XML data. This header is useful in HTTP Post and Put requests.

    这些是Restful Web服务中的重要标头。 Accept标头告诉Web服务客户端正在接受哪种响应,因此,如果Web服务能够以XML和JSON格式发送响应,并且客户端将Accept标头发送为“ application / xml”,则将发送XML响应。 对于Accept标头“ application / json”,服务器将发送JSON响应。

    Content-Type标头用于告诉服务器请求中发送的数据格式是什么。 如果Content-Type标头为“ application / xml”,则服务器将尝试将其解析为XML数据。 此标头在HTTP Post和Put请求中很有用。

  21. 您如何在SOAP和REST Web服务之间进行选择? (How would you choose between SOAP and REST web services?)

    Web Services work on client-server model and when it comes to choose between SOAP and REST, it all depends on project requirements. Let’s look at some of the conditions affecting our choice:

    • Do you know your web service clients beforehand? If Yes, then you can define a contract before implementation and SOAP seems better choice. But if you don’t then REST seems better choice because you can provide sample request/response and test cases easily for client applications to use later on.
    • How much time you have? For quick implementation REST is the best choice. You can create web service easily, test it through browser/curl and get ready for your clients.
    • What kind of data format are supported? If only XML then you can go with SOAP but if you think about supporting JSON also in future then go with REST.

    Web服务在客户端-服务器模型上工作,在SOAP和REST之间进行选择时,这完全取决于项目要求。 让我们看一些影响我们选择的条件:

    • 您事先了解您的Web服务客户端吗? 如果是,那么您可以在实现之前定义一个合同,SOAP似乎是更好的选择。 但是,如果您不这样做,那么REST似乎是更好的选择,因为您可以轻松提供示例请求/响应和测试用例,以供客户端应用程序以后使用。
    • 你有多少时间? 为了快速实施,REST是最佳选择。 您可以轻松创建Web服务,通​​过浏览器/卷曲对其进行测试,并为您的客户做好准备。
    • 支持哪种数据格式? 如果仅使用XML,则可以使用SOAP,但是如果将来考虑支持JSON,则可以使用REST。
  22. 什么是JAX-WS API? (What is JAX-WS API?)

    JAX-WS stands for Java API for XML Web Services. JAX-WS is XML based Java API to build web services server and client application. It’s part of standard Java API, so we don’t need to include anything else which working with it. Refer to JAX-WS Tutorial for a complete example.

    JAX-WS代表XML Web Services的Java API。 JAX-WS是基于XML的Java API,用于构建Web服务服务器和客户端应用程序。 它是标准Java API的一部分,因此我们不需要包括其他任何与之兼容的东西。 有关完整的示例,请参考《 JAX-WS教程 》。

  23. 用Java命名一些框架来实现SOAP Web服务吗? (Name some frameworks in Java to implement SOAP web services?)

    We can create SOAP web services using JAX-WS API, however some of the other frameworks that can be used are Apache Axis and Apache CXF. Note that they are not implementations of JAX-WS API, they are totally different framework that work on Servlet model to expose your business logic classes as SOAP web services. Read more at Java SOAP Web Service Eclipse example.

    我们可以使用JAX-WS API创建SOAP Web服务,但是可以使用的其他一些框架是Apache Axis和Apache CXF。 请注意,它们不是JAX-WS API的实现,它们是完全不同的框架,可以在Servlet模型上工作,以将您的业务逻辑类公开为SOAP Web服务。 在Java SOAP Web Service Eclipse示例中内容。

  24. 命名JAX-WS API中使用的重要注释? (Name important annotations used in JAX-WS API?)

    Some of the important annotations used in JAX-WS API are:

    • @WebService
    • @SOAPBinding
    • @WebMethod

    JAX-WS API中使用的一些重要注释是:

    • @网络服务
    • @SOAPBinding
    • @WebMethod
  25. javax.xml.ws.Endpoint类的用途是什么? (What is use of javax.xml.ws.Endpoint class?)

    Endpoint class provides useful methods to create endpoint and publish existing implementation as web service. This comes handy in testing web services before making further changes to deploy it on actual server.

    端点类提供了有用的方法来创建端点并将现有的实现发布为Web服务。 在进行进一步更改以将其部署到实际服务器上之前,这在测试Web服务时非常方便。

  26. RPC样式和文档样式SOAP Web服务之间有什么区别? (What is the difference between RPC Style and Document Style SOAP web Services?)

    RPC style generate WSDL document based on the method name and it’s parameters. No type definitions are present in WSDL document.
    Document style contains type and can be validated against predefined schema. Let’s look at these with a simple program. Below is a simple test program where I am using Endpoint to publish my simple SOAP web service.

    TestService.java

    package com.journaldev.jaxws.service;import javax.jws.WebMethod;
    import javax.jws.WebService;
    import javax.jws.soap.SOAPBinding;
    import javax.xml.ws.Endpoint;@WebService
    @SOAPBinding(style = SOAPBinding.Style.RPC)
    public class TestService {@WebMethodpublic String sayHello(String msg){return "Hello "+msg;}public static void main(String[] args){Endpoint.publish("https://localhost:8888/testWS", new TestService());}
    }

    When I run above program and then access the WSDL, it gives me below XML.

    rpc.xml

    Notice that types element is empty and we can’t validate it against any schema. Now just change the SOAPBinding.Style.RPC to SOAPBinding.Style.DOCUMENT and you will get below WSDL.

    document.xml

    <?xml version='1.0' encoding='UTF-8'?>
    <!-- Published by JAX-WS RI (https://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b. --><!-- Generated by JAX-WS RI (https://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b. -->
    <definitions xmlns:wsu="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="https://www.w3.org/ns/ws-policy" xmlns:wsp1_2="https://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="https://www.w3.org/2007/05/addressing/metadata" xmlns:soap="https://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="https://service.jaxws.journaldev.com/" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns="https://schemas.xmlsoap.org/wsdl/" targetNamespace="https://service.jaxws.journaldev.com/" name="TestServiceService">
    <types>
    <xsd:schema>
    <xsd:import namespace="https://service.jaxws.journaldev.com/" schemaLocation="https://localhost:8888/testWS?xsd=1"/>
    </xsd:schema>
    </types>
    <message name="sayHello">
    <part name="parameters" element="tns:sayHello"/>
    </message>
    <message name="sayHelloResponse">
    <part name="parameters" element="tns:sayHelloResponse"/>
    </message>
    <portType name="TestService">
    <operation name="sayHello">
    <input wsam:Action="https://service.jaxws.journaldev.com/TestService/sayHelloRequest" message="tns:sayHello"/>
    <output wsam:Action="https://service.jaxws.journaldev.com/TestService/sayHelloResponse" message="tns:sayHelloResponse"/>
    </operation>
    </portType>
    <binding name="TestServicePortBinding" type="tns:TestService">
    <soap:binding transport="https://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="sayHello">
    <soap:operation soapAction=""/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    </binding>
    <service name="TestServiceService">
    <port name="TestServicePort" binding="tns:TestServicePortBinding">
    <soap:address location="https://localhost:8888/testWS"/>
    </port>
    </service>
    </definitions>

    Open schemaLocation URL in browser and you will get below XML.

    schemaLocation.xml

    So here WSDL document can be validated against the schema definintion.

    RPC样式根据方法名称及其参数生成WSDL文档。 WSDL文档中没有类型定义。
    文档样式包含类型,并且可以针对预定义的架构进行验证。 让我们用一个简单的程序看看这些。 下面是一个简单的测试程序,我在其中使用Endpoint发布我的简单SOAP Web服务。

    TestService.java

    package com.journaldev.jaxws.service;import javax.jws.WebMethod;
    import javax.jws.WebService;
    import javax.jws.soap.SOAPBinding;
    import javax.xml.ws.Endpoint;@WebService
    @SOAPBinding(style = SOAPBinding.Style.RPC)
    public class TestService {@WebMethodpublic String sayHello(String msg){return "Hello "+msg;}public static void main(String[] args){Endpoint.publish("https://localhost:8888/testWS", new TestService());}
    }

    当我在上面的程序中运行然后访问WSDL时,它在XML下面给出了我。

    rpc.xml

    请注意, types元素为空,我们无法针对任何架构对其进行验证。 现在,只需将SOAPBinding.Style.RPC更改为SOAPBinding.Style.DOCUMENT ,您将获得以下WSDL。

    document.xml

    <?xml version='1.0' encoding='UTF-8'?>
    <!-- Published by JAX-WS RI (https://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b. --><!-- Generated by JAX-WS RI (https://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b. -->
    <definitions xmlns:wsu="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="https://www.w3.org/ns/ws-policy" xmlns:wsp1_2="https://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="https://www.w3.org/2007/05/addressing/metadata" xmlns:soap="https://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="https://service.jaxws.journaldev.com/" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns="https://schemas.xmlsoap.org/wsdl/" targetNamespace="https://service.jaxws.journaldev.com/" name="TestServiceService">
    <types>
    <xsd:schema>
    <xsd:import namespace="https://service.jaxws.journaldev.com/" schemaLocation="https://localhost:8888/testWS?xsd=1"/>
    </xsd:schema>
    </types>
    <message name="sayHello">
    <part name="parameters" element="tns:sayHello"/>
    </message>
    <message name="sayHelloResponse">
    <part name="parameters" element="tns:sayHelloResponse"/>
    </message>
    <portType name="TestService">
    <operation name="sayHello">
    <input wsam:Action="https://service.jaxws.journaldev.com/TestService/sayHelloRequest" message="tns:sayHello"/>
    <output wsam:Action="https://service.jaxws.journaldev.com/TestService/sayHelloResponse" message="tns:sayHelloResponse"/>
    </operation>
    </portType>
    <binding name="TestServicePortBinding" type="tns:TestService">
    <soap:binding transport="https://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="sayHello">
    <soap:operation soapAction=""/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    </binding>
    <service name="TestServiceService">
    <port name="TestServicePort" binding="tns:TestServicePortBinding">
    <soap:address location="https://localhost:8888/testWS"/>
    </port>
    </service>
    </definitions>

    在浏览器中打开schemaLocation URL,您将获得以下XML。

    schemaLocation.xml

    因此,这里的WSDL文档可以根据模式定义进行验证。

  27. 如何获取SOAP Web服务的WSDL文件? (How to get WSDL file of a SOAP web service?)

    WSDL document can be accessed by appending ?wsdl to the SOAP endoint URL. In above example, we can access it at https://localhost:8888/testWS?wsdl location.

    可以通过将?wsdl附加到SOAP endint URL来访问WSDL文档。 在上面的示例中,我们可以在https://localhost:8888/testWS?wsdl位置访问它。

  28. 什么是sun-jaxws.xml文件? (What is sun-jaxws.xml file?)

    This file is used to provide endpoints details when JAX-WS web services are deployed in servlet container such as Tomcat. This file is present in WEB-INF directory and contains endpoint name, implementation class and URL pattern. For example;

    sun-jaxws.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <endpoints xmlns="https://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0"><endpointname="PersonServiceImpl"implementation="com.journaldev.jaxws.service.PersonServiceImpl"url-pattern="/personWS"/>
    </endpoints>

    当JAX-WS Web服务部署在servlet容器(例如Tomcat)中时,此文件用于提供端点详细信息。 该文件位于WEB-INF目录中,并且包含端点名称,实现类和URL模式。 例如;

    sun-jaxws.xml

  29. 什么是JAX-RS API? (What is JAX-RS API?)

    Java API for RESTful Web Services (JAX-RS) is the Java API for creating REST web services. JAX-RS uses annotations to simplify the development and deployment of web services. JAX-RS is part of JDK, so you don’t need to include anything to use it’s annotations.

    RESTful Web服务的Java API(JAX-RS)是用于创建REST Web服务的Java API。 JAX-RS使用注释来简化Web服务的开发和部署。 JAX-RS是JDK的一部分,因此您无需包括任何内容即可使用其注释。

  30. 列举一些JAX-RS API的实现? (Name some implementations of JAX-RS API?)

    There are two major implementations of JAX-RS API.

    1. Jersey: Jersey is the reference implementation provided by Sun. For using Jersey as our JAX-RS implementation, all we need to configure its servlet in web.xml and add required dependencies. Note that JAX-RS API is part of JDK not Jersey, so we have to add its dependency jars in our application.
    2. RESTEasy: RESTEasy is the JBoss project that provides JAX-RS implementation.

    JAX-RS API有两种主要实现。

    1. 泽西岛:泽西岛是Sun提供的参考实现。 为了使用Jersey作为我们的JAX-RS实现,我们需要在web.xml中配置其servlet并添加所需的依赖项。 请注意,JAX-RS API是JDK而不是Jersey的一部分,因此我们必须在应用程序中添加其依赖项jar。
    2. RESTEasy:RESTEasy是提供JAX-RS实现的JBoss项目。
  31. 什么是wsimport实用程序? (What is wsimport utility?)

    We can use wsimport utility to generate the client stubs. This utility comes with standard installation of JDK. Below image shows an example execution of this utility for one of JAX-WS project.

    我们可以使用wsimport实用程序生成客户端存根。 该实用程序随JDK的标准安装一起提供。 下图显示了JAX-WS项目之一的此实用程序的示例执行。

  32. 命名JAX-RS API中使用的重要注释? (Name important annotations used in JAX-RS API?)

    Some of the important JAX-RS annotations are:

    • @Path: used to specify the relative path of class and methods. We can get the URI of a webservice by scanning the Path annotation value.
    • @GET, @PUT, @POST, @DELETE and @HEAD: used to specify the HTTP request type for a method.
    • @Produces, @Consumes: used to specify the request and response types.
    • @PathParam: used to bind the method parameter to path value by parsing it.

    一些重要的JAX-RS批注是:

    • @Path :用于指定类和方法的相对路径。 我们可以通过扫描路径注释值来获取Web服务的URI。
    • @GET@PUT@POST@DELETE@HEAD :用于指定的方法的HTTP请求类型。
    • @Produces@Consumes :用于指定请求和响应类型。
    • @PathParam :用于通过解析将方法参数绑定到路径值。
  33. @XmlRootElement注释的用途是什么? (What is the use of @XmlRootElement annotation?)

    XmlRootElement annotation is used by JAXB to transform java object to XML and vice versa. So we have to annotate model classes with this annotation.

    JAXB使用XmlRootElement批注将Java对象转换为XML,反之亦然。 因此,我们必须使用此注释对模型类进行注释。

  34. 如何在HTTP响应中设置不同的状态码? (How to set different status code in HTTP response?)

    For setting HTTP status code other than 200, we have to use javax.ws.rs.core.Response class for response. Below are some of the sample return statements showing it’s usage.

    return Response.status(422).entity(exception).build();
    return Response.ok(response).build(); //200

    For a complete example, please read RESTEasy Tutorial.

    要设置除200外的HTTP状态代码,我们必须使用javax.ws.rs.core.Response类进行响应。 以下是一些示例返回语句,显示了其用法。

    有关完整示例,请阅读RESTEasy教程 。

That’s all for web services interview questions, let me know what you think about it through comments. If you think that I have missed some important questions, please let me know through comments and I will be happy to answer them and add to the list.

这就是Web服务面试问题的全部内容,请通过评论告诉我您的想法。 如果您认为我错过了一些重要问题,请通过评论让我知道,我很乐意回答并添加到列表中。

翻译自: https://www.journaldev.com/9193/web-services-interview-questions-soap-restful

restful soap

restful soap_Web服务面试问题– SOAP,RESTful相关推荐

  1. 带有Jersey的JAX-RS教程,用于RESTful Web服务

    在当今世界,数据扮演着非常重要的角色. 如此众多的应用程序将各种类型的数据用于不同的操作,所以最重要的方面是应用程序之间的通信. 当应用程序可以通信时,它们之间的数据共享变得容易. 就像在亚洲运行的应 ...

  2. restful web_泽西岛的RESTful Web服务

    restful web 我已经讨论了有关体系结构考虑事项<< link >>的早期文章,以成为可在我的系统/机器上使用的分布式环境上的RESTful系统. 本文我们将讨论如何基 ...

  3. 泽西岛的RESTful Web服务

    我已经讨论了有关体系结构注意事项<< link >>的早期文章,以成为可在我的系统/机器上使用的分布式环境上的RESTful系统. 本文我们将讨论如何基于REST体系结构考虑来 ...

  4. SpringBoot调用RESTful Web服务

    SpringBoot调用RESTful Web服务 本指南将引导您完成创建使用RESTful Web服务的应用程序的过程. 你会建立什么 您将RestTemplate在https://gturnqui ...

  5. Spring Boot 构建RESTful Web服务

    Spring Boot 构建RESTful Web服务 本指南将引导您完成使用Spring 创建" Hello World" RESTful Web服务的过程. 你会建立什么 您将 ...

  6. jersey tomcat MySQL_基于jersey和Apache Tomcat构建Restful Web服务(一)

    基于jersey和Apache Tomcat构建Restful Web服务(一) 现如今,RESTful架构已然成为了最流行的一种互联网软件架构,它结构清晰.符合标准.易于理解.扩展方便,所以得到越来 ...

  7. 面试 restful_RESTful Web服务面试问题

    面试 restful We have written a lot on Restful Web Services, today we will look into Restful web servic ...

  8. resteasy_Tomcat 7上具有RESTeasy JAX-RS的RESTful Web服务– Eclipse和Maven项目

    resteasy 开发Web服务的RESTful方法不断受到越来越多的关注,并且似乎正在将SOAP淘汰. 我不会讨论哪种方法更好,但是我相信我们都同意REST更轻量级. 在本教程中,我将向您展示如何使 ...

  9. 使用Java的RESTful Web服务

    REST代表"代表性状态转移",由Roy Fielding于2000年在其论文"建筑风格和基于网络的软件体系结构设计"中首次提出. REST是一种建筑风格. H ...

最新文章

  1. 从互联网大厂裸辞 500 天后,我发生哪些变化?
  2. nagios2------添加监控对象
  3. Linux 基础——查看文件内容的命令
  4. chrome java虚拟机_JATT:谷歌的Java虚拟机自动调整工具
  5. 图论基础知识--最小生成树算法kruskal(克鲁斯克尔)和普里姆算法(Prim算法);最短路径算法Dijkstra(迪杰斯特拉)和Floyd(弗洛伊德)
  6. [Android]Hello, Android!
  7. MySQL备份---lvm snapshot
  8. 惠普136a芯片清零_怎么把惠普打印机芯片清零
  9. Tomcat8安装(或卸载重装)
  10. 参数化三维管网建模系统MagicPipe3D
  11. matlab 仿真光学实验报告,光学信息处理实验的Matlab仿真.doc
  12. 差分放大电路及动态分析
  13. 聚类分析在用户行为中的实例_聚类分析案例
  14. excel表格数据汇总计数如何完成?
  15. 让Kodu动起来---Kodu少儿编程第五天
  16. HOOK拦截消息代码
  17. hbase region in transition
  18. 省级面板数据(2000-2019)七:价格指数(居民消费、零售、生产、投资)(stata版)
  19. 40-网上商城数据库-商品类别数据操作(一)
  20. “蔚来杯“2022牛客暑期多校训练营1

热门文章

  1. layout_weight
  2. Asp.net MVC - 使用PRG模式(附源码)
  3. [转载] 使用Python中的NLTK和spaCy删除停用词与文本标准化
  4. verilog之编程应该注意的事项
  5. Oracle入门第二天(下)——单行函数
  6. MVC部分视图的使用
  7. 《深入理解Spark:核心思想与源码分析》——SparkContext的初始化(叔篇)——TaskScheduler的启动...
  8. XSS CSRF 攻击
  9. 修改ORACLE RAC的字符集(记录一下)
  10. RCNN学习笔记(1):Rich feature hierarchies for accurate object detection and semantic segmentation