简体   繁体   English

WSE 3.0 - 字节数组被编码为Base64而不是“MTOM-ing”到二进制

[英]WSE 3.0 - Byte array being encoded as Base64 and not “MTOM-ing” to binary

I have a couple of other questions on here surrounding this area but they are a bit redundant now. 关于这个区域,我还有其他一些问题,但现在它们有点多余。 Any answers to them would also be appreciated but this question is my main concern at the minute. 对他们的任何答案也会受到赞赏,但这个问题是我当下的主要关注点。

I have followed lots of examples of how MTOM/XOP works in WSE 3.0 and have set up my project exactly as it seems is required. 我已经跟踪了许多关于MTOM / XOP如何在WSE 3.0中工作的示例,并且已经完全按照看起来需要设置了我的项目。 I have a Byte array field that is designated as DataType:-base64Binary. 我有一个字节数组字段,指定为DataType:-base64Binary。 In this I put the Byte array of the attachment I want to add. 在这个我把我要添加的附件的字节数组。 When I run the application and check the request, the data is encoded inline as base64, ie without the XOP Include element and associated MIME part. 当我运行应用程序并检查请求时,数据内联编码为base64,即没有XOP Include元素和关联的MIME部分。

My understanding of MTOM within WSE 3.0 was that, when encoding it will take any field designated as base64Binary and encode it as binary and move it to a MIME part, replacing it with an XOP Include element. 我对WSE 3.0中的MTOM的理解是,在编码时,它将把任何字段指定为base64Binary并将其编码为二进制并将其移动到MIME部分,将其替换为XOP Include元素。 That is to say, it just worked. 也就是说,它只是奏效了。 But I have set the service, in the Reference file, to inherit Microsoft.Web.Services3.WebServicesClientProtocol and have set the RequireMtom flag to true, and it is still not encoding correctly. 但是我已经在Reference文件中设置了服务来继承Microsoft.Web.Services3.WebServicesClientProtocol并将RequireMtom标志设置为true,并且它仍然没有正确编码。

Have I missed something here? 我错过了什么吗? Is there any other steps that should be implemented for this to work? 是否还有其他步骤可以实现?

EDIT: After looking through my code for the 100th time, I am wondering if it might be due to the fact that I have to serialise the payload before running the ProcessMessage method. 编辑:在第100次查看我的代码后,我想知道是否可能是因为我必须在运行ProcessMessage方法之前序列化有效负载。 Does this sound like it could be a problem? 这听起来像是一个问题吗? The reason we have serialised is because the method we have to use accepts a "Payload" parameter which has a content property, this content property is an XMLElement property and the only way we can get this is to serialise the required class. 我们序列化的原因是因为我们必须使用的方法接受具有content属性的“Payload”参数,此content属性是XMLElement属性,我们唯一可以得到的方法是序列化所需的类。 But does this stop the MTOM recognising the data type of the base64 field and therefore not converted to binary with the MIME parts and XOP? 但这是否会阻止MTOM识别base64字段的数据类型,因此不会使用MIME部分和XOP转换为二进制? Just really clutching at straws now. 现在真的抓着稻草。

EDIT 2: While I have a solution below, the third party company are now saying that our namespace prefixes are wrong! 编辑2:虽然我有一个解决方案,但第三方公司现在说我们的命名空间前缀是错误的! We have something like <q1:Attachment xmlns:q1="http://whatever" /> and they are demanding it be <s:Attachment xmlns:s="http://whatever" /> . 我们有类似<q1:Attachment xmlns:q1="http://whatever" /> ,他们要求<s:Attachment xmlns:s="http://whatever" /> Am I going mad or does that not matter? 我生气还是不重要? Is there a way I can tell it how to assign the namespace prefixes? 有没有办法告诉它如何分配名称空间前缀?

Ok I finally figured it out and it was to do with the serialisation before invoking the method. 好吧,我终于想出来了,它是在调用方法之前使用序列化。 I rewrote the class that was passed in to the method so it didn't require an XMLElement as a property, and therefore a pre-serialised class, and passed that in. This works correctly, after only 3 or 4 weeks of work...If anyone wants more clarification I can try to get it down here. 我重写了传入方法的类,因此它不需要将XMLElement作为属性,因此不需要预先序列化的类,并将其传入。这只能在工作3或4周后正常工作。如果有人想要更多澄清,我可以试着把它弄到这里。

EDIT: In response to John Saunders comment. 编辑:回应约翰桑德斯的评论。 When I say pre-serialised I mean that the class, containing the byte array, was serialised to XML before sending within the web method. 当我说预序列化时,我的意思是包含字节数组的类在Web方法中发送之前被序列化为XML。 This was due to the fact that the class that was being sent in the web method only accepted an XMLElement. 这是因为在Web方法中发送的类只接受了XMLElement。 I reworked the class, that was the parameter of the web method, to accept the other class without being serialised to XML beforehand. 我重新编写了类,即web方法的参数,接受另一个类而不事先将其序列化为XML。

Ie. IE浏览器。 This is how the class looks now. 这就是班级现在的样子。 The processRepairOrder field and PRO() property were added and used instead of the anyField processRepairOrder字段和PRO()属性已添加并使用,而不是anyField

Partial Public Class Content

    Private anyField As System.Xml.XmlElement

    Private idField As String

    Private anyAttrField() As System.Xml.XmlAttribute

    'This was added
    Private processRepairOrder As ProcessRepairOrder

    'This was added
    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute([ElementName]:="ProcessRepairOrder", [Namespace]:="http://www.starstandards.org/STAR")> _
    Public Property PRO() As ProcessRepairOrder
        Get
            Return Me.processRepairOrder
        End Get
        Set(ByVal value As ProcessRepairOrder)
            Me.processRepairOrder = value
        End Set
    End Property


    '''<remarks/>
    <System.Xml.Serialization.XmlAnyElementAttribute()> _
    Public Property Any() As System.Xml.XmlElement
        Get
            Return Me.anyField
        End Get
        Set(ByVal value As System.Xml.XmlElement)
            Me.anyField = value
        End Set
    End Property

    '''<remarks/>
    <System.Xml.Serialization.XmlAttributeAttribute(DataType:="token")> _
    Public Property id() As String
        Get
            Return Me.idField
        End Get
        Set(ByVal value As String)
            Me.idField = value
        End Set
    End Property

    '''<remarks/>
    <System.Xml.Serialization.XmlAnyAttributeAttribute()> _
    Public Property AnyAttr() As System.Xml.XmlAttribute()
        Get
            Return Me.anyAttrField
        End Get
        Set(ByVal value As System.Xml.XmlAttribute())
            Me.anyAttrField = value
        End Set
    End Property
End Class

With regards to the specific namespaces, we added another field to the required classes as such: 关于特定的命名空间,我们在所需的类中添加了另一个字段:

<System.Xml.Serialization.XmlNamespaceDeclarations()> _
Public xmlns As XmlSerializerNamespaces

Then we were able to add the namespace by using: 然后我们可以使用以下命令添加命名空间:

Dim ns As New Serialization.XmlSerializerNamespaces
ns.Add("s", "http://whatever")

class.xmlns = ns 

I know it's been long time ago but... 我知道它已经很久以前但是......

I have the same thing happening and as it turns out my byte array gets in-lined when its 767 bytes or smaller :) And it gets moved to separate part when its 768 (12 * 8 * 8) bytes or larger. 我发生了同样的事情,事实证明我的byte数组在767字节或更小的情况下得到内联:)当它的768(12 * 8 * 8)字节或更大时,它会被移动到单独的部分。

So it just varies on content size. 所以它只是内容大小不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM