如何使用 WCF(或 WSE 3)在 Web 服务客户端应用程序的请求和响应中混合消息编码类型(文本/MTOM)?

2024-04-01

这是我的问题。我正在访问一个 Web 服务(托管在基于 Java 的服务器上),该服务仅接受文本编码的请求,但它返回 MTOM 响应。我发现,如果我将 Web 服务设置为 RequireMtom,它会发送 Mtom 请求!不幸的是,服务器因 Mtom 请求而阻塞并返回 500 错误。但是,如果我将其设置为文本消息编码,则响应会正确返回,并带有多部分 MIME (MTOM) 响应,该响应会导致 Microsoft Web 服务 API 出错(下面的示例错误)。它期待一个文本编码的响应,因为请求是文本编码的。我只想要求 RequireMtom 回复。有人能帮我一下吗?

正如您在下面的错误中看到的(在标准 Web 服务 API、WCF 或 WSE3 中发生),当我使用文本编码发送请求时,响应会正确返回,其中包含多部分/相关响应中的所有数据,但是.net框架窒息!

WSE 的错误消息:

Client found response content type of 'multipart/related; type="text/xml"; start="<1AE0B46A85B0186B5D136D12E1EE286E>";  boundary="----=_Part_209564_1891070135.1226526701833"', but expected 'text/xml'.
The request failed with the error message:

 at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at TestWseService.AdesaJasperWse.ManagementServiceService.runReport(String requestXmlString) in C:\Documents and Settings\xxx\My Documents\Visual Studio 2005\Projects\TestWseService\Web References\AdesaJasperWse\Reference.cs:line 229
   at TestWseService.Form1.buttonRunService_Click(Object sender, EventArgs e) in C:\Documents and Settings\xxx\My Documents\Visual Studio 2005\Projects\TestWseService\Form1.cs:line 42

WCF 的错误消息

The content type multipart/related; type="text/xml"; start="<30ED8FE3004CDA67723CC7164A6CFEEC>";    boundary="----=_Part_209545_389093169.1226526546805" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: 

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

请求(带有短信编码):

POST /jasperserver-pro/services/repository HTTP/1.1
Content-Type: text/xml; charset=utf-8
VsDebuggerCausalityData: uIDPo7V2+runH+xGudbec7ueUU8AAAAA7H9vL3stlkCBofMgLa5DWkQOHHpBdy1Ek6P6nXx7FpsACQAA
SOAPAction: ""
Authorization: Basic amFzcGVyYWRtaW46akBzcDNyQGRtJW4=
Host: reports.dev.xxx.com
Content-Length: 789
Expect: 100-continue

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><q1:runReport xmlns:q1="http://axis2.ws.jasperserver.jaspersoft.com"><requestXmlString xsi:type="xsd:string">&lt;request operationName="runReport" locale="en"&gt;&#xD;
&lt;argument name="RUN_OUTPUT_FORMAT"&gt;HTML&lt;/argument&gt;&#xD;
&lt;resourceDescriptor name="" wsType="" uriString="/BusinessIntelligence/MOS/Reports/dotnettest" isNew="false"&gt;&#xD;
&lt;label&gt;null&lt;/label&gt;&#xD;
&lt;parameter name="testparam"&gt;1&lt;/parameter&gt;&#xD;
&lt;/resourceDescriptor&gt;&#xD;
&lt;/request&gt;</requestXmlString></q1:runReport></s:Body></s:Envelope>

响应(带有文本消息编码):

HTTP/1.1 200 OK
Date: Wed, 12 Nov 2008 21:49:04 GMT
Server: IBM_HTTP_Server
Surrogate-Control: no-store
Set-Cookie: JSESSIONID=0000z5pH1xEMyulueASctjru2qe:13kftunf6; Path=/
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-cache="set-cookie, set-cookie2"
Content-Length: 2580
Content-Type: multipart/related; type="text/xml"; start="<30ED8FE3004CDA67723CC7164A6CFEEC>";   boundary="----=_Part_209545_389093169.1226526546805"
Content-Language: en-US


------=_Part_209545_389093169.1226526546805
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <30ED8FE3004CDA67723CC7164A6CFEEC>

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:runReportResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://axis2.ws.jasperserver.jaspersoft.com"><runReportReturn xsi:type="xsd:string">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;operationResult version=&quot;2.0.1&quot;&gt;
    &lt;returnCode&gt;&lt;![CDATA[0]]&gt;&lt;/returnCode&gt;
&lt;/operationResult&gt;
</runReportReturn></ns1:runReportResponse></soapenv:Body></soapenv:Envelope>
------=_Part_209545_389093169.1226526546805
Content-Type: text/html
Content-Transfer-Encoding: binary
Content-Id: <report>

<html>
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <style type="text/css">
    a {text-decoration: none}
  </style>
</head>
<body text="#000000" link="#000000" alink="#000000" vlink="#000000">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td width="50%">&nbsp;</td><td align="center">

<a name="JR_PAGE_ANCHOR_0_1"/>
<table style="width: 595px" cellpadding="0" cellspacing="0" border="0" bgcolor="white">
<tr>
  <td><img alt="" src="images/px" style="width: 35px; height: 1px;"/></td>
  <td><img alt="" src="images/px" style="width: 189px; height: 1px;"/></td>
  <td><img alt="" src="images/px" style="width: 253px; height: 1px;"/></td>
  <td><img alt="" src="images/px" style="width: 118px; height: 1px;"/></td>
</tr>
<tr valign="top">
  <td colspan="4"><img alt="" src="images/px" style="width: 595px; height: 20px;"/></td>
</tr>
<tr valign="top">
  <td><img alt="" src="images/px" style="width: 35px; height: 30px;"/></td>
  <td valign="middle"><span style="font-family: Arial; font-size: 12.0px; font-weight: bold;">The value of the parameter is:</span></td>
  <td valign="middle"><span style="font-family: Arial; background-color: #FFFFFF; font-size: 12.0px; font-weight: bold;">1</span></td>
  <td><img alt="" src="images/px" style="width: 118px; height: 30px;"/></td>
</tr>
<tr valign="top">
  <td colspan="4"><img alt="" src="images/px" style="width: 595px; height: 20px;"/></td>
</tr>
</table>

</td><td width="50%">&nbsp;</td></tr>
</table>
</body>
</html>

------=_Part_209545_389093169.1226526546805--

请求(使用 Mtom 消息编码):

POST /jasperserver-pro/services/repository HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:fafcdca7-94f7-4884-a8d4-5c6d50dbe8ef+id=1";start-info="text/xml"
VsDebuggerCausalityData: uIDPo+cN2kKX2odFuUVaER0j60gAAAAAmfYaGH7Ow0WQOcwhebh5pqmDl29omcVOtwVGa10IWewACQAA
SOAPAction: ""
Authorization: Basic amFzcGVyYWRtaW46akBzcDNyQGRtJW4=
Host: reports.dev.xxx.com
Content-Length: 1031
Expect: 100-continue


--uuid:fafcdca7-94f7-4884-a8d4-5c6d50dbe8ef+id=1
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><q1:runReport xmlns:q1="http://axis2.ws.jasperserver.jaspersoft.com"><requestXmlString xsi:type="xsd:string">&lt;request operationName="runReport" locale="en"&gt;&#xD;
&lt;argument name="RUN_OUTPUT_FORMAT"&gt;HTML&lt;/argument&gt;&#xD;
&lt;resourceDescriptor name="" wsType="" uriString="/BusinessIntelligence/MOS/Reports/dotnettest" isNew="false"&gt;&#xD;
&lt;label&gt;null&lt;/label&gt;&#xD;
&lt;parameter name="testparam"&gt;1&lt;/parameter&gt;&#xD;
&lt;/resourceDescriptor&gt;&#xD;
&lt;/request&gt;</requestXmlString></q1:runReport></s:Body></s:Envelope>
--uuid:fafcdca7-94f7-4884-a8d4-5c6d50dbe8ef+id=1--

响应(使用 Mtom 消息编码):

HTTP/1.1 500 Internal Server Error
Date: Wed, 12 Nov 2008 21:47:42 GMT
Server: IBM_HTTP_Server
Surrogate-Control: no-store
$WSEP: 
Set-Cookie: JSESSIONID=0000_iMrdp-TnK9FG3jZFzjx_hA:13kftunf6; Path=/
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-cache="set-cookie, set-cookie2"
Content-Length: 12
Connection: close
Content-Type: text/html;charset=UTF-8
Content-Language: en-US

Error 500: 

以下是支持 Microsoft 不支持混合编码理论的链接:

WSE 3.0:MTOM 请求强制要求 MTOM 响应吗? http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/9270913a-ab9f-4097-beef-51d4d69563d7/

UHG!


是的,您可以使用 WCF 发送短信并获得 mtom 回复(反之亦然)。

see...

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/480f1bc4-1fc4-40e9-a2ed-efcf3009d6ef http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/480f1bc4-1fc4-40e9-a2ed-efcf3009d6ef

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 WCF(或 WSE 3)在 Web 服务客户端应用程序的请求和响应中混合消息编码类型(文本/MTOM)? 的相关文章

  • 两个 RichTextBox 具有相同的滚动条

    是否有任何可用的第三方工具有两个富文本框 但两者只有一个共享滚动条 我需要用两种不同的语言实现一些文本 但两个文本框应该同时滚动 public enum ScrollBarType uint SbHorz 0 SbVert 1 SbCtl
  • 有条件地在 Visual Studio 中嵌入资源 (C#)

    有没有办法有条件地将资源嵌入到 NET 项目中 IE 如果我定义了 INCLUDETHIS 那么我想要将某个大文件嵌入到 dll 中 否则我不希望它嵌入 我知道我可以做两个项目来做到这一点 但我希望在一个项目中完成这一切 使用该文件的代码很
  • 删除匹配前的一个单词和一个单词

    匹配之前的一个单词可以是一组任何符号 例如 D E F 我有一个正则表达式 s w s XXX 输入示例 This is KKK M D D xXx PPP输出示例 This is KKK PPP 所以我需要删除 XXX 之前的 1 个单词
  • 生成逗号分隔值

    假设我有一个字符串集合 foo bar xyz 我想从列表中生成一个逗号分隔的值 如下所示 foo bar xyz 请注意末尾缺少 我知道有多种方法可以生成此内容 使用 for 循环和 string Format 或 StringBuild
  • WCF WebHttp 混合身份验证(基本和匿名)

    所有这些都与 WebHttp 绑定有关 托管在自定义服务主机中 IIS 目前不是一个选项 我已经实现了自定义 UserNamePasswordValidator 和自定义 IAuthorizationPolicy 当我将端点的绑定配置为使用
  • 如何在 Windows CE 中使用 VB.Net 访问条码扫描仪

    最近我被要求开发一个应用程序摩托罗拉 MK4000 http www motorola com Business US EN Business Product and Services Micro Kiosks Micro Kiosks M
  • PrivateObject 找不到属性

    我的结构基本上如下所示 abstract class A protected string Identificator get set private void DoSomething DoSomethingSpecific protect
  • 使用 IdentityDbContext 和 Code First 自动迁移表位置和架构的实体框架?

    我正在尝试使用 IdentityDbContext 类设置自动迁移更新 并将更改传播到整个数据库的实际 DbContext 在进入代码之前 在使用自动迁移实现 IdentityDbContext 时 我收到此错误 影响迁移历史系统表位置的自
  • Axis2 错误:要输出的文本中的空白字符 (0x4) 无效

    我创建了一个 Java 客户端 使用 Axis2 1 7 6 作为代码生成器与 SOAP Web 服务进行交互 问题在于客户端的某些输入抛出异常并显示以下消息 org apache axis2 AxisFault Invalid white
  • 如何 XML 序列化 DateTimeOffset 属性?

    The DateTimeOffset当数据表示为 Xml 时 我在此类中拥有的属性不会呈现 我需要做什么来告诉 Xml 序列化将其正确呈现为DateTime or DateTimeOffset XmlRoot playersConnecte
  • Lightspeed 与 NHibernate

    有什么体验光速 http www mindscape co nz products LightSpeed comparison aspx Mindscape 提供的比较并没有过多说明 NHibernate Lightspeed 看起来很灵活
  • 为什么 EF 5.0 在编译为 sql 时不支持此 EF 4.x LINQ 语法?

    我有一些代码最近从 EF 4 2 升级到 EF 5 0 实际上是 EF 4 4 因为我在 Net 4 0 上运行 我发现我必须更改查询的语法 我很好奇为什么 让我从问题开始 我有一个由客户端定期填充的事件日志表 对于每个事件日志 都会在报告
  • MVC2 中隐藏字段的替代方案

    我有一个 viewModel 其中包含一个在传递给部分视图之前填充的字符串 我需要能够在发布表单时取回数据 目前我已经创建了一个隐藏字段并将数据绑定到它 然后 当回发时 我可以从表单集合中获取数据 这并不完全是我想要的 我希望数据完全隐藏在
  • WCF 与 .Net 远程处理

    根据本文 http msdn microsoft com en us library bb310550 aspx 带有命名管道的WCF是IPC的最佳选择 它比 Net Remoting快25 左右 我有以下代码 将 WCF 与命名管道与 N
  • Python tkinter.filedialog Askfolder 干扰 clr

    我主要在 Spyder 中工作 构建需要弹出文件夹或文件浏览窗口的脚本 下面的代码在spyder中完美运行 在 Pycharm 中 askopenfilename工作良好 同时askdirectory什么都不做 卡住了 但是 如果在调试模式
  • TextBox 焦点的 WinForms 事件?

    我想添加一个偶数TextBox当它有焦点时 我知道我可以用一个简单的方法来做到这一点textbox1 Focus并检查布尔值 但我不想那样做 我想这样做 this tGID Focus new System EventHandler thi
  • 为什么密码错误会导致“填充无效且无法删除”?

    我需要一些简单的字符串加密 所以我编写了以下代码 有很多 灵感 来自here http www codeproject com KB security DotNetCrypto aspx create and initialize a cr
  • 从 Orchard 内的主题渲染图像

    我刚刚选择 Orchard 来构建我的博客 作为创建这个新博客的努力的一部分 我正在创建一个自定义主题 这个自定义主题同时具有 CSS 和图像 我的问题 我的问题基本上可以归结为 如何渲染属于主题一部分的图像 到目前为止我已经尝试过的 我尝
  • string.Compare 行为

    怎么会这样呢 这是从VS2008中的立即窗口获取的 string Compare 1 string Compare 0 0 1 从言论来看字符串比较 http msdn microsoft com en us library 84787k2
  • 过期时自动重新填充缓存

    我当前缓存方法调用的结果 缓存代码遵循标准模式 如果存在 则使用缓存中的项目 否则计算结果 在返回之前将其缓存以供将来调用 我想保护客户端代码免受缓存未命中的影响 例如 当项目过期时 我正在考虑生成一个线程来等待缓存对象的生命周期 然后运行

随机推荐

  • 返回多个结果集的查询

    我有一个MSSQL数据库并正在运行以下查询 select from projects select from user 上面的查询一次返回两个结果集 我无法单独触发这两个查询 如何在 Java 类中同时处理两个结果集 处理多个的正确代码Re
  • 用 emacs 替换 ssh+screen+editor

    我的目标是远程编写代码 到目前为止 我一直在使用 ssh screen 编辑器 例如 vim 我知道使用本地 emacs 或 vim 可以编辑远程文件 但是 一旦本地 emacs 关闭并且我想重新打开它 或使用另一台计算机打开它 我需要再次
  • 如何调整 matplotlib 中每隔一行子图之间的间距

    我希望水平调整子图之间的空间 特别是在每隔两行之间 我可以使用调整每一行fig subplots adjust hspace n 但是否可以将其应用于每第二行 import matplotlib pyplot as plt fig ax p
  • 如何使用CNN来训练不同大小的输入数据?

    CNN 似乎主要针对固定大小的输入来实现 现在我想用CNN来训练一些不同大小的句子 有哪些常用的方法 以下建议主要与用于计算机视觉任务 特别是识别 的 CNN 相关 但也可能对您的领域有所帮助 我会看看He 等人的 用于视觉识别的深度卷积网
  • Android - onBackPressed() 不工作

    我有一个针对 Android 2 1 构建的应用程序 我想覆盖后退按钮 我按照这里的例子 http android developers blogspot com 2009 12 01 archive html http android d
  • tkinter tkMessageBox html 链接

    我在 python tkinter 应用程序中出现了 tkMEssagebox showerror 当有人无法使用应用程序登录时 tkMessageBox showerror 中是否可以有 url 链接 ie tkMessageBox sh
  • 代码说“尝试比较数字<=实例”

    It says Players ninjafox56 PlayerGui Shop ShopGui LightSide ChooseSideL 5 尝试比较数字 Rank game Players LocalPlayer leadersta
  • 使用 Jenkins Sonar 插件成功构建后,Sonar 不显示代码覆盖率

    我正在尝试使用 Sonar 和 Jenkins 来获得代码覆盖率 我看到 Jenkins 的 Sonar 插件成功执行了 JUnit 测试用例并成功完成了构建 但 Sonar 不会在项目上显示代码覆盖率结果 代码覆盖率始终显示 0 0 但声
  • 从 firebase 数据库 flutter 读取项目列表

    我正在尝试从此数据库中构建项目列表 但我收到此错误 TypeError type List
  • 让 Ada(用 GNAT 编译)从当前目录外部导入文件?

    我正在大学学习编程入门课程 选择的语言是 Ada 我正在 Kate 中编码并使用 GNAT 4 6 3 进行编译 我们必须为我们的程序使用教师提供的库 如下所示 with foo use foo 当然 然后文件foo adb必须包含在与我的
  • Tensorflow-GPU 仍在 CPU 上处理

    Tensorflow GPU 版本 1 4 0 CUDA 版本 8 0 cuDNN v6 0 nvidia smi 的输出 NVIDIA SMI 388 59 Driver Version 388 59 GPU Name TCC WDDM
  • Kendo Grid 层次结构从主网格传递 ID

    我有一个 Kendo 层次网格 其中主网格包含Client详细信息和子网格包含Point of Contacts 我能够通过Client ID从主网格进入子网格Read操作和数据加载正常 然而 问题是在通过的时候出现的Client ID i
  • 存在哪些基于 Python 的仪表板选项? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我想在每台服务器上创建一个仪表板来显示其运行状况和一些日常处理的结果 我计划连接 shell 脚本和 Python 程序来收集数据 我认为
  • Jquery匹配具有相同id/class的多个元素

    我正在努力在特定元素的宽度小于 50 时显示消息 但是有多个具有相同类的元素 并且只有页面中的第一个元素显示消息 这是 jsfiddlehttp jsfiddle net MaNdn 23 http jsfiddle net MaNdn 2
  • PHP/MySQL 消息系统

    你好 我正在尝试用 php 和 mysql 制作一个消息系统 mysql表很简单 ID 发件人 接收者 文本 时间戳 我试图让消息传递有点像 Facebook Twitter 所以列表位于 对话 中 并且对话中的最后一条消息被查看 这是我的
  • 如何从 FirebaseAuth 获取 ID 令牌

    我正在从 firebase 数据库中读取一些 Json 文件 并尝试获取当前用户的 ID 令牌以在标头中使用 如下所示 var response await httpClient get url headers Authorization
  • Excel 数据读取器问题、列名称和工作表选择

    我在用Excel 数据阅读器 https exceldatareader codeplex com 将一些数据读入实体框架数据库 下面的代码可以工作 但我需要一些进一步的改进 首先 IsFirstRowAsColumnNames 似乎没有按
  • javaw.exe和eclipse启动问题

    我正在尝试使用 eclipse juno 但即使在阅读了这里的许多页面后 仍然会出现错误 当我尝试使用 C Users eclipse eclipse exe vm JAVA HOME bin javaw exe data C 命令行启动
  • 释放二叉树而不使用递归

    指的是这个问题C 中的解除分配二叉树结构 https stackoverflow com questions 32733353 deallocating binary tree structure in c noredirect 1 com
  • 如何使用 WCF(或 WSE 3)在 Web 服务客户端应用程序的请求和响应中混合消息编码类型(文本/MTOM)?

    这是我的问题 我正在访问一个 Web 服务 托管在基于 Java 的服务器上 该服务仅接受文本编码的请求 但它返回 MTOM 响应 我发现 如果我将 Web 服务设置为 RequireMtom 它会发送 Mtom 请求 不幸的是 服务器因