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

相关文章

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关

C++ 函数 strftime 和时间格式示例详解

《C++函数strftime和时间格式示例详解》strftime是C/C++标准库中用于格式化日期和时间的函数,定义在ctime头文件中,它将tm结构体中的时间信息转换为指定格式的字符串,是处理... 目录C++ 函数 strftipythonme 详解一、函数原型二、功能描述三、格式字符串说明四、返回值五

C++作用域和标识符查找规则详解

《C++作用域和标识符查找规则详解》在C++中,作用域(Scope)和标识符查找(IdentifierLookup)是理解代码行为的重要概念,本文将详细介绍这些规则,并通过实例来说明它们的工作原理,需... 目录作用域标识符查找规则1. 普通查找(Ordinary Lookup)2. 限定查找(Qualif

C/C++ chrono简单使用场景示例详解

《C/C++chrono简单使用场景示例详解》:本文主要介绍C/C++chrono简单使用场景示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友... 目录chrono使用场景举例1 输出格式化字符串chrono使用场景China编程举例1 输出格式化字符串示

C++/类与对象/默认成员函数@构造函数的用法

《C++/类与对象/默认成员函数@构造函数的用法》:本文主要介绍C++/类与对象/默认成员函数@构造函数的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录名词概念默认成员函数构造函数概念函数特征显示构造函数隐式构造函数总结名词概念默认构造函数:不用传参就可以

C++类和对象之默认成员函数的使用解读

《C++类和对象之默认成员函数的使用解读》:本文主要介绍C++类和对象之默认成员函数的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、默认成员函数有哪些二、各默认成员函数详解默认构造函数析构函数拷贝构造函数拷贝赋值运算符三、默认成员函数的注意事项总结一

C/C++中OpenCV 矩阵运算的实现

《C/C++中OpenCV矩阵运算的实现》本文主要介绍了C/C++中OpenCV矩阵运算的实现,包括基本算术运算(标量与矩阵)、矩阵乘法、转置、逆矩阵、行列式、迹、范数等操作,感兴趣的可以了解一下... 目录矩阵的创建与初始化创建矩阵访问矩阵元素基本的算术运算 ➕➖✖️➗矩阵与标量运算矩阵与矩阵运算 (逐元

C/C++的OpenCV 进行图像梯度提取的几种实现

《C/C++的OpenCV进行图像梯度提取的几种实现》本文主要介绍了C/C++的OpenCV进行图像梯度提取的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录预www.chinasem.cn备知识1. 图像加载与预处理2. Sobel 算子计算 X 和 Y

C/C++和OpenCV实现调用摄像头

《C/C++和OpenCV实现调用摄像头》本文主要介绍了C/C++和OpenCV实现调用摄像头,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录准备工作1. 打开摄像头2. 读取视频帧3. 显示视频帧4. 释放资源5. 获取和设置摄像头属性

c/c++的opencv图像金字塔缩放实现

《c/c++的opencv图像金字塔缩放实现》本文主要介绍了c/c++的opencv图像金字塔缩放实现,通过对原始图像进行连续的下采样或上采样操作,生成一系列不同分辨率的图像,具有一定的参考价值,感兴... 目录图像金字塔简介图像下采样 (cv::pyrDown)图像上采样 (cv::pyrUp)C++ O