序言异常中不允许的内容 [英] content not allowed in prolog exception

查看:18
本文介绍了序言异常中不允许的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 xml 发送到第三方通过 ac#.NET 应用程序提供给我的基于 Java 的 Web 服务,但出现 org.xml.sax.SAXParseException: Content is not allowed in序言 错误.

I am trying to send xml to a java-based web service given to me by a third party via a c#.NET application, and I get the org.xml.sax.SAXParseException: Content is not allowed in prolog error.

我已根据架构验证了 xml,并将用于保存 xml 的内存流传递到 .xml 文件,然后使用十六进制编辑器打开该文件以确保 prolog 中没有不需要的字符,并且没有.打开时,文件中的第一个字符是

I have verified the xml against the schema, and I passed the memorystream I am using to hold the xml to an .xml file, then opened the file with a hex editor to make sure that there were no undesired characters in the prolog, and there are none. When opened, the first characters in the file are

<?xml version="1.0" encoding="utf-8"?>

我被用来将 xml 数据发送到 Web 服务的类接受一个字节数组.我认为使用 XmlTextWriter 创建 xml 到 utf-8 编码的内存流,然后将流的内容发送到字节数组是最直接的方法.

The class I was given to use to send the xml data to the web service accepts a byte array. I figure that creating the xml using an XmlTextWriter to a utf-8 encoded memorystream, then sending the contents of the stream to a byte array is the most direct method.

我做了很多研究,并尝试了我能找到的围绕这个问题的所有可能性,但没有任何效果.有人可以帮忙吗?提前致谢.

I have done a lot of research and tried all the possbilities around this issue that I could find, but nothing works. Could someone please help? Thanks in advance.

顺便说一下,这是 Web 服务返回给我的部分内容.在 SOAP 消息的负载中, 元素之后的数据应该是这样的,还是应该像之前的内容一样可读 xml?

By the way, here is a portion of what the web service returns to me. In the payload of the SOAP message, should the data after the element look like that, or be readable xml like the content before it?

Messages:
Message:

Payload: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http:/
/schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema
-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><postSubmissi
on xmlns="http://service.arm.hud.gov/"><submissionHeader><agcHcsId>1</agcHcsId><
agcName>test</agcName><systemName>123</systemName><cmsSubId>123456</cmsSubId><su
bFlag>0</subFlag></submissionHeader><agcType>test</agcType><submissionData>PD94b
WwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48dG5zOlN1Ym1pc3Npb25EYXRhIHhzaTpzY
2hlbWFMb2NhdGlvbj0iaHR0cDovL2dvdi5odWQuYXJtL2FybV9kYXRhYmFnXzNfMS54c2QiIHhtbG5zO
nhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxT......etc............................
</submissionData></postSubmission></soap:Body></soap:Envelope>

这里是 xml 数据以提高可读性:

Here the xml data for better readability:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http:/
    /schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema
    -instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <postSubmissi on xmlns="http://service.arm.hud.gov/">
            <submissionHeader>
                <agcHcsId>1</agcHcsId>
                <agcName>test</agcName>
                <systemName>123</systemName>
                <cmsSubId>123456</cmsSubId>
                <subFlag>0</subFlag>
            </submissionHeader>
            <agcType>test</agcType>
            <submissionData>PD94b
                WwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48dG5zOlN1Ym1pc3Npb25EYXRhIHhzaTpzY
                2hlbWFMb2NhdGlvbj0iaHR0cDovL2dvdi5odWQuYXJtL2FybV9kYXRhYmFnXzNfMS54c2QiIHhtbG5zO
                nhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxT......etc............................
            </submissionData>
        </postSubmission>
    </soap:Body>
</soap:Envelope>

推荐答案

我能够通过删除 UTF 编码来解决这个问题.听起来在我们的两个案例中,文本实际上都不是 UTF-8 编码的.

I was able to get rid of the problem by removing the UTF encoding. Sounds like in both of our cases, the text wasn't actually UTF-8 encoded.

这篇关于序言异常中不允许的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆