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

相关文章

c++ 类成员变量默认初始值的实现

《c++类成员变量默认初始值的实现》本文主要介绍了c++类成员变量默认初始值,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录C++类成员变量初始化c++类的变量的初始化在C++中,如果使用类成员变量时未给定其初始值,那么它将被

C++中NULL与nullptr的区别小结

《C++中NULL与nullptr的区别小结》本文介绍了C++编程中NULL与nullptr的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编... 目录C++98空值——NULLC++11空值——nullptr区别对比示例 C++98空值——NUL

C++ Log4cpp跨平台日志库的使用小结

《C++Log4cpp跨平台日志库的使用小结》Log4cpp是c++类库,本文详细介绍了C++日志库log4cpp的使用方法,及设置日志输出格式和优先级,具有一定的参考价值,感兴趣的可以了解一下... 目录一、介绍1. log4cpp的日志方式2.设置日志输出的格式3. 设置日志的输出优先级二、Window

从入门到精通C++11 <chrono> 库特性

《从入门到精通C++11<chrono>库特性》chrono库是C++11中一个非常强大和实用的库,它为时间处理提供了丰富的功能和类型安全的接口,通过本文的介绍,我们了解了chrono库的基本概念... 目录一、引言1.1 为什么需要<chrono>库1.2<chrono>库的基本概念二、时间段(Durat

C++20管道运算符的实现示例

《C++20管道运算符的实现示例》本文简要介绍C++20管道运算符的使用与实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录标准库的管道运算符使用自己实现类似的管道运算符我们不打算介绍太多,因为它实际属于c++20最为重要的

Visual Studio 2022 编译C++20代码的图文步骤

《VisualStudio2022编译C++20代码的图文步骤》在VisualStudio中启用C++20import功能,需设置语言标准为ISOC++20,开启扫描源查找模块依赖及实验性标... 默认创建Visual Studio桌面控制台项目代码包含C++20的import方法。右键项目的属性:

python删除xml中的w:ascii属性的步骤

《python删除xml中的w:ascii属性的步骤》使用xml.etree.ElementTree删除WordXML中w:ascii属性,需注册命名空间并定位rFonts元素,通过del操作删除属... 可以使用python的XML.etree.ElementTree模块通过以下步骤删除XML中的w:as

c++中的set容器介绍及操作大全

《c++中的set容器介绍及操作大全》:本文主要介绍c++中的set容器介绍及操作大全,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录​​一、核心特性​​️ ​​二、基本操作​​​​1. 初始化与赋值​​​​2. 增删查操作​​​​3. 遍历方

解析C++11 static_assert及与Boost库的关联从入门到精通

《解析C++11static_assert及与Boost库的关联从入门到精通》static_assert是C++中强大的编译时验证工具,它能够在编译阶段拦截不符合预期的类型或值,增强代码的健壮性,通... 目录一、背景知识:传统断言方法的局限性1.1 assert宏1.2 #error指令1.3 第三方解决

C++11委托构造函数和继承构造函数的实现

《C++11委托构造函数和继承构造函数的实现》C++引入了委托构造函数和继承构造函数这两个重要的特性,本文主要介绍了C++11委托构造函数和继承构造函数的实现,具有一定的参考价值,感兴趣的可以了解一下... 目录引言一、委托构造函数1.1 委托构造函数的定义与作用1.2 委托构造函数的语法1.3 委托构造函