c++中literal_XML Web Services中的Doc / Literal / Bare-我对此的看法。

2024-03-18 17:20

本文主要是介绍c++中literal_XML Web Services中的Doc / Literal / Bare-我对此的看法。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

c++中literal

c++中literal

Apparently Craig Andera and Tim Ewald were recently working on an MSDN code rewrite and were talking about building doc/literal/bare Web Services vs. doc/literal/wrapped.

显然,克雷格·安德拉( Craig Andera)和蒂姆·埃瓦尔德( Tim Ewald )最近正在着手进行MSDN代码重写,并在讨论构建doc / literal / bare Web Services与doc / literal / wrapped。

I'm a little confused by their respective posts, as they appear to say too different things.  (Coming up on Fox, When Smart People Disagree!) They were both in the same house, coding the same stuff, but Craig's conclusion about how to use SoapParameterStyle.Bare is very different than Tim's (and mine).

我对他们各自的职位有些困惑,因为他们似乎说了太多不同的话。 (出现在Fox上,当聪明人不同意! )他们俩都在同一间屋子里,编码相同的东西,但是Craig关于如何使用SoapParameterStyle.Bare的结论与Tim(和我的)有很大不同。

Tim suggests that getting an AddResponse type "for free" when writing code like this:

蒂姆建议在编写如下代码时“免费”获得AddResponse类型:

//SDH: This is bad, avoid it[WebMethod]
[return: XmlElement("sum")]
public int Add(int x, int y) { return x + y; }

// SDH:这很糟糕,请避免[WebMethod] [返回:XmlElement(“ sum”)] public int Add(int x,int y){return x + y; }

is lame, and I agree.  The generared AddResponse type is totally magic, coming (by magic) from the Method name, which is a little too tightly-coupled for my tastes.

la脚,我同意。 通用的AddResponse类型完全是魔术,来自于Method名称(通过魔术),这对我来说有点太紧密了。

Instead, your functions should take as parameters and return as reponses formal types that you control.  Then you can use the [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)] attribute to avoid any extra automagically-added wrapped elements.  This is purely a coding convention, it's not expressed in WSDL. 

相反,您的函数应以参数为参数,并以响应形式返回控制的形式类型。 然后,可以使用[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]属性来避免任何多余的自动添加的包装元素。 这纯粹是一种编码约定,未在WSDL中表达。

//SDH: This is not bad, embrace it.[WebMethod]
[SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)]
[return: XmlElement("AddResponse")]
public AddResponse Add(AddRequest req)
{
  AddResponse resp = new AddResponse();
  resp = req.x + req.y;
  return resp;
}

// SDH:这还不错,拥抱它。 [WebMethod] [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)] [返回:XmlElement(“ AddResponse”)] 公共AddResponse Add(AddRequest请求) { AddResponse resp =新的AddResponse(); resp = req.x + req.y; 回报}

Tim's right on with this.  We do the same thing at Corillian with our code-generation stuff (maybe I'll present on it sometime.)  You can reuse the Request and Response messages this way, as well as take and return base classes.

蒂姆对此表示赞同。 在Corillian,我们用代码生成的东西做同样的事情(也许我会在某个时候出现。)您可以通过这种方式重用Request和Response消息,以及获取和返回基类。

However, Craig had a different view.  He simply added the bare attribute to the method call:

但是,克雷格有不同的看法。 他只是将裸属性添加到方法调用中:

//SDH: This is bad, think twice
[WebMethod]
[SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare)]
public int Add(int x, int y) { return x + y; }

// SDH:这很糟糕,请三思[WebMethod] [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)] public int Add(int x,int y){return x + y; }

which results in

导致

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <x xmlns="http://tempuri.org/">int</x>
    <y xmlns="http://tempuri.org/">int</y>
  </soap:Body>
</soap:Envelope>

<?xml版本=“ 1.0”编码=“ utf-8”?> <soap:Envelope xmlns:xsi =“ http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd =“ http://www.w3.org/2001/XMLSchema” xmlns:soap =“ http://schemas.xmlsoap.org/soap/envelope/”> <soap:Body> <x xmlns =“ http://tempuri.org/”> int </ x> <y xmlns =“ http://tempuri.org/”> int </ y> </ soap:Body> </ soap:信封>

Which is a non-WS-I Basic Profile compliant Web Service, as it has more than one child node under <soap:Body>.  Craig muses "To me, this just seems like nicer XML; more like how I would do it if I were just using XmlWriter and raw sockets."  I totally disagree with that statement, as XML Web Services are decidedly NOT about that level of abstraction.  If you like talking with XmlWriter and raw sockets, why not yank the <soap:envelope> and those pesky namespaces? ;) If so, there's already a spec for you. 

这是不符合WS-I基本概要文件的Web服务,因为它在<soap:Body>下具有多个子节点。 Craig缪斯说: “对我来说,这看起来像是更好的XML;更像是如果我仅使用XmlWriter和原始套接字,该怎么做。” 我完全不同意该声明,因为XML Web Services绝对与该抽象级别无关。 如果您喜欢使用XmlWriter和原始套接字,为什么不使用<soap:envelope>和那些讨厌的名称空间呢? ;)如果是这样,那么已经有适合您的规范。

Additionally this places even more pressure on the HTTP SOAPAction header, which was always a bad idea.  Fundamentally (at least in my World View) SOAP messages should be transport neutral and that's what wsa:Action is for.

另外,这给HTTP SOAPAction标头带来了更大的压力,这始终是一个坏主意。 从根本上(至少在我的世界视图中),SOAP消息应该是传输无关的,这就是wsa:Action的目的。

So, conclusion?  Be explicit.  Use Request and Response messages as ins and outs for your Web Services, call them out and use SoapParameterStyle.Bare to avoid the extra wrapping element.  Tim's list of reasons why is excellent.

那么,结论呢? 要明确。 将请求消息和响应消息用作Web服务的内容,调用它们并使用SoapParameterStyle.Bare以避免多余的包装元素。 蒂姆之所以出色的原因清单。

翻译自: https://www.hanselman.com/blog/docliteralbare-in-xml-web-services-my-thoughts-on-all-this

c++中literal

这篇关于c++中literal_XML Web Services中的Doc / Literal / Bare-我对此的看法。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/823060

相关文章

Python利用ElementTree实现快速解析XML文件

《Python利用ElementTree实现快速解析XML文件》ElementTree是Python标准库的一部分,而且是Python标准库中用于解析和操作XML数据的模块,下面小编就来和大家详细讲讲... 目录一、XML文件解析到底有多重要二、ElementTree快速入门1. 加载XML的两种方式2.

C++如何通过Qt反射机制实现数据类序列化

《C++如何通过Qt反射机制实现数据类序列化》在C++工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作,所以本文就来聊聊C++如何通过Qt反射机制实现数据类序列化吧... 目录设计预期设计思路代码实现使用方法在 C++ 工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作。由于数据类

Spring 基于XML配置 bean管理 Bean-IOC的方法

《Spring基于XML配置bean管理Bean-IOC的方法》:本文主要介绍Spring基于XML配置bean管理Bean-IOC的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一... 目录一. spring学习的核心内容二. 基于 XML 配置 bean1. 通过类型来获取 bean2. 通过

Linux下如何使用C++获取硬件信息

《Linux下如何使用C++获取硬件信息》这篇文章主要为大家详细介绍了如何使用C++实现获取CPU,主板,磁盘,BIOS信息等硬件信息,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录方法获取CPU信息:读取"/proc/cpuinfo"文件获取磁盘信息:读取"/proc/diskstats"文

C++使用printf语句实现进制转换的示例代码

《C++使用printf语句实现进制转换的示例代码》在C语言中,printf函数可以直接实现部分进制转换功能,通过格式说明符(formatspecifier)快速输出不同进制的数值,下面给大家分享C+... 目录一、printf 原生支持的进制转换1. 十进制、八进制、十六进制转换2. 显示进制前缀3. 指

C++中初始化二维数组的几种常见方法

《C++中初始化二维数组的几种常见方法》本文详细介绍了在C++中初始化二维数组的不同方式,包括静态初始化、循环、全部为零、部分初始化、std::array和std::vector,以及std::vec... 目录1. 静态初始化2. 使用循环初始化3. 全部初始化为零4. 部分初始化5. 使用 std::a

C++ vector的常见用法超详细讲解

《C++vector的常见用法超详细讲解》:本文主要介绍C++vector的常见用法,包括C++中vector容器的定义、初始化方法、访问元素、常用函数及其时间复杂度,通过代码介绍的非常详细,... 目录1、vector的定义2、vector常用初始化方法1、使编程用花括号直接赋值2、使用圆括号赋值3、ve

使用Python将JSON,XML和YAML数据写入Excel文件

《使用Python将JSON,XML和YAML数据写入Excel文件》JSON、XML和YAML作为主流结构化数据格式,因其层次化表达能力和跨平台兼容性,已成为系统间数据交换的通用载体,本文将介绍如何... 目录如何使用python写入数据到Excel工作表用Python导入jsON数据到Excel工作表用

如何高效移除C++关联容器中的元素

《如何高效移除C++关联容器中的元素》关联容器和顺序容器有着很大不同,关联容器中的元素是按照关键字来保存和访问的,而顺序容器中的元素是按它们在容器中的位置来顺序保存和访问的,本文介绍了如何高效移除C+... 目录一、简介二、移除给定位置的元素三、移除与特定键值等价的元素四、移除满足特android定条件的元

Python获取C++中返回的char*字段的两种思路

《Python获取C++中返回的char*字段的两种思路》有时候需要获取C++函数中返回来的不定长的char*字符串,本文小编为大家找到了两种解决问题的思路,感兴趣的小伙伴可以跟随小编一起学习一下... 有时候需要获取C++函数中返回来的不定长的char*字符串,目前我找到两种解决问题的思路,具体实现如下: