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开发PDF转Doc格式小程序

《基于Python开发PDF转Doc格式小程序》这篇文章主要为大家详细介绍了如何基于Python开发PDF转Doc格式小程序,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 用python实现PDF转Doc格式小程序以下是一个使用Python实现PDF转DOC格式的GUI程序,采用T

C++ Primer 标准库vector示例详解

《C++Primer标准库vector示例详解》该文章主要介绍了C++标准库中的vector类型,包括其定义、初始化、成员函数以及常见操作,文章详细解释了如何使用vector来存储和操作对象集合,... 目录3.3标准库Vector定义和初始化vector对象通列表初始化vector对象创建指定数量的元素值

web网络安全之跨站脚本攻击(XSS)详解

《web网络安全之跨站脚本攻击(XSS)详解》:本文主要介绍web网络安全之跨站脚本攻击(XSS)的相关资料,跨站脚本攻击XSS是一种常见的Web安全漏洞,攻击者通过注入恶意脚本诱使用户执行,可能... 目录前言XSS 的类型1. 存储型 XSS(Stored XSS)示例:危害:2. 反射型 XSS(Re

C++实现回文串判断的两种高效方法

《C++实现回文串判断的两种高效方法》文章介绍了两种判断回文串的方法:解法一通过创建新字符串来处理,解法二在原字符串上直接筛选判断,两种方法都使用了双指针法,文中通过代码示例讲解的非常详细,需要的朋友... 目录一、问题描述示例二、解法一:将字母数字连接到新的 string思路代码实现代码解释复杂度分析三、

C++一个数组赋值给另一个数组方式

《C++一个数组赋值给另一个数组方式》文章介绍了三种在C++中将一个数组赋值给另一个数组的方法:使用循环逐个元素赋值、使用标准库函数std::copy或std::memcpy以及使用标准库容器,每种方... 目录C++一个数组赋值给另一个数组循环遍历赋值使用标准库中的函数 std::copy 或 std::

C++使用栈实现括号匹配的代码详解

《C++使用栈实现括号匹配的代码详解》在编程中,括号匹配是一个常见问题,尤其是在处理数学表达式、编译器解析等任务时,栈是一种非常适合处理此类问题的数据结构,能够精确地管理括号的匹配问题,本文将通过C+... 目录引言问题描述代码讲解代码解析栈的状态表示测试总结引言在编程中,括号匹配是一个常见问题,尤其是在

使用C++实现链表元素的反转

《使用C++实现链表元素的反转》反转链表是链表操作中一个经典的问题,也是面试中常见的考题,本文将从思路到实现一步步地讲解如何实现链表的反转,帮助初学者理解这一操作,我们将使用C++代码演示具体实现,同... 目录问题定义思路分析代码实现带头节点的链表代码讲解其他实现方式时间和空间复杂度分析总结问题定义给定

C#中读取XML文件的四种常用方法

《C#中读取XML文件的四种常用方法》Xml是Internet环境中跨平台的,依赖于内容的技术,是当前处理结构化文档信息的有力工具,下面我们就来看看C#中读取XML文件的方法都有哪些吧... 目录XML简介格式C#读取XML文件方法使用XmlDocument使用XmlTextReader/XmlTextWr

C++初始化数组的几种常见方法(简单易懂)

《C++初始化数组的几种常见方法(简单易懂)》本文介绍了C++中数组的初始化方法,包括一维数组和二维数组的初始化,以及用new动态初始化数组,在C++11及以上版本中,还提供了使用std::array... 目录1、初始化一维数组1.1、使用列表初始化(推荐方式)1.2、初始化部分列表1.3、使用std::

C++ Primer 多维数组的使用

《C++Primer多维数组的使用》本文主要介绍了多维数组在C++语言中的定义、初始化、下标引用以及使用范围for语句处理多维数组的方法,具有一定的参考价值,感兴趣的可以了解一下... 目录多维数组多维数组的初始化多维数组的下标引用使用范围for语句处理多维数组指针和多维数组多维数组严格来说,C++语言没