5

我使用部署在 WebLogic 10.3 上的 JAX-WS (v2.1.3 - Sun JDK 1.6.0_05) 开发了一个 Web 服务,当我使用 Java 客户端或 SoapUI 或其他 Web 服务测试工具时它工作得很好。我需要使用 2005 Microsoft SQL Server Reporting Services 使用此服务,我收到以下错误

由于异常而无法创建 SOAP 消息:XML 阅读器错误:意外字符内容

SEVERE: Couldn't create SOAP message due to exception: XML reader error: unexpected character content: "?"
com.sun.xml.ws.protocol.soap.MessageCreationException: Couldn't create SOAP message due to exception: XML reader error: unexpected character content: "?"
at com.sun.xml.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:292)
at com.sun.xml.ws.transport.http.HttpAdapter.decodePacket(HttpAdapter.java:276)
at com.sun.xml.ws.transport.http.HttpAdapter.access$500(HttpAdapter.java:93)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:432)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:134)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: com.sun.xml.ws.streaming.XMLStreamReaderException: XML reader error: unexpected character content: "?"
at com.sun.xml.ws.streaming.XMLStreamReaderUtil.nextElementContent(XMLStreamReaderUtil.java:102)
at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:174)
at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:296)
at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:128)
at com.sun.xml.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:287)
... 22 more

如果我使用 HTTP 代理来检测 SSRS 发送到 JAX-WS 的内容,我会将 EF BB BF 视为帖子正文的开头,而 JAX-WS 不喜欢这样。如果我删除特殊字符并使用 Fiddler 重新提交请求,那么 Web 服务调用将起作用。

为什么 JAX-WS 会因标准 UTF-8 BOM 而崩溃?是否有解决此问题的解决方法?任何建议将不胜感激。谢谢

——文尼

4

3 回答 3

2

We had a similar problem writing a .Net client to a 3rd party Java webservice, .Net included the Byte order mark and the Java service would throw an exception.

The 3rd party SOAP method took a single string as an argument, and that string was an XML document (I love people who don't really understand what problem SOAP is trying to solve!) By default .net added the UTF-8 byte order mark to the "payload" xml document, which is strictly correct, but in practice causes problems.

In our case we found two possible solutions from the client (.net) end. I'm not sure how easy this will be to do from SQL Reporting services though.

String.Trim() - The xml had to get put into a string before passing into the soap method, calling .Trim() removed the byte order mark. Easy.

The second method was to set the UTF encoding settings on the XmlWriterSettings slightly differently, something like the following:

XmlWriter xmlWriter = null;
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = new UTF8Encoding(false);
xmlWriter = XmlWriter.Create(xmlSteam, settings);

The important bit is the "new UTF8Encoding(false);", that argument is "encoderShouldEmitUTF8Identifier" and pretty much solves the problem.

于 2010-09-14T12:23:48.807 回答
1

一种解决方法的想法:在将请求文档传递给 JAX-WS 服务之前,在仅使用 BOM 的 Web 应用程序上添加过滤器。

于 2009-10-28T20:20:06.687 回答
0

我们在托管由 Java 客户端使用的 .NET WCF 服务时遇到了这个问题。

.NET 服务使用SoapCore,因此我们的解决方案是修改服务器应用程序的编码选项:

var encoder = new SoapEncoderOptions();
encoder.WriteEncoding = new UTF8Encoding(false); // <---- disables BOM which causes issue

app.UseEndpoints(endpoints => {
    endpoints.UseSoapEndpoint<IPingService>("/Service.svc", encoder, SoapSerializer.DataContractSerializer);
});

这是在查看Microsoft 的 UTF-8 编码文档后发现的。

SoapCore 存储库中的一个问题提到了相同的内容:https ://github.com/DigDes/SoapCore/issues/394 。

于 2021-12-29T18:49:30.393 回答