gpt4 book ai didi

.net - 从 header 中删除某些元素 - 由 WSE 3.0 创建

转载 作者:数据小太阳 更新时间:2023-10-29 02:46:18 24 4
gpt4 key购买 nike

我正在使用 wsdl,它会自动将额外的元素添加到 xml 中。为了使其符合不使用这些元素的外部 Web 服务。请参见下图: http://img406.imageshack.us/img406/1307/differencese.png左 = 红色元素需要移除 - 右 = 我需要它输出什么

我附上了创建信封和有效负载的代码。

    Dim content As myProxy.Content = New myProxy.Content
Dim inputguid As String = Guid.NewGuid.ToString
Dim service As myProxy.WebService = New myProxy.WebService
Dim str As New System.Xml.XmlDocument
Dim payload As myProxy.Payload = New myProxy.Payload

'payload
str.LoadXml(xmlstr)

'manifest
service.payloadManifest = New myProxy.PayloadManifest
service.payloadManifest.manifest = New myProxy.Manifest() {New myProxy.Manifest}
service.payloadManifest.manifest(0).element = "GetVehicleServiceHistory"
service.payloadManifest.manifest(0).namespaceURI = ""
service.payloadManifest.manifest(0).contentID = "Content0"
service.payloadManifest.manifest(0).version = "2.01"
service.SoapVersion = SoapProtocolVersion.Soap11

service.UserAgent = "Jakarta Commons-HttpClient/3.1"
Dim usertoken As New Microsoft.Web.Services3.Security.Tokens.UsernameToken("userid", "password", Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendPlainText)

service.RequestSoapContext.Security.Tokens.Add(usertoken)
service.RequestSoapContext.Security.MustUnderstand = False

payload.content = New myProxy.Content() {content}
ReDim Preserve payload.content(0)
payload.content(0).Any = str.DocumentElement
payload.content(0).id = "Content0"

service.Url = "http://localhost:8080"
service.ProcessMessage(payload)

如有任何帮助,我们将不胜感激。

迈克尔

最佳答案

你可以写一个 SoapExtension .我过去这样做是为了从 SOAP 响应中清除非法字符,但您也可以使用它来修改您的请求。基本上,它会在发送 SOAP 包之前拦截它,或者在您收到它时,但在 .Net 反序列化它之前拦截它。

Stefan Goßner 有一篇旧博客文章解释了 how build a SoapExtension .您可以将代码放在 ProcessOutput 方法中。

缺点是您将 SOAP 消息解析为文本,但当然可以将其加载到 XDocumentXmlDocument 中(如果效果更好的话)。但您之后也会将其作为文本传递。

如果您使用的是 WCF,请查看 Intercept messages in a WCF Client ,因为您必须为 SOAP 拦截实现 IClientMessageInspector

希望这对您有所帮助。

关于.net - 从 header 中删除某些元素 - 由 WSE 3.0 创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8311987/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com