none
MTOM messages must have type 'application/xop+xml' RRS feed

  • Question

  • I'm using C# to call a Java Webservice. Fiddler gives me a status of 200. So my call to the service is good. But something in the .NET does not like my MTOM message. Any ideas? Here are all the details.

    I'm getting this error:

    MTOM messages must have type 'application/xop+xml'.

    I found this post on stackoverflow which talks about creating a custom encoder.  https://stackoverflow.com/questions/17175231/wcf-error-creating-reader-for-mtom-message

    I'm currently taking on the task of creating a custom encoder but having some issues with the overriding of the WriteMessage.

    public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
    {
                return this.textEncoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
    }

    When I use the code from above the attachment is not sent in the request.  So currently I'm stuck on changing the WriteMessage function to send my soap request with an attachment.  Once I figure that out.  Then I can focus on changing the content type in the ReadMessage method.  

    Anybody has any ideas on how change the WriteMessage so I can send the attachment also? 

    Thanks!

    Friday, March 30, 2018 5:37 PM

All replies

  • Here is what the stack trace says:

     at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader()
       at System.ServiceModel.Channels.BufferedMessageData.GetMessageReader()
       at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState, Boolean[] understoodHeaders, Boolean understoodHeadersModified)
       at System.ServiceModel.Channels.MtomMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType)
       at System.ServiceModel.Channels.HttpInput.DecodeBufferedMessage(ArraySegment`1 buffer, Stream inputStream)
       at System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream)
       at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(HttpRequestMessage httpRequestMessage, Exception& requestException)
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.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.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at ESARWS.ESAR.CORETransaction.COREEnvelopeBatchSubmission(COREEnvelopeBatchSubmissionRequest request)
       at ESARWS.ESAR.CORETransactionClient.ESARWS.ESAR.CORETransaction.COREEnvelopeBatchSubmission(COREEnvelopeBatchSubmissionRequest request) in C:\Project\xxxWS\Service References\ESAR\Reference.cs:line 665
       at ESARWS.ESAR.CORETransactionClient.COREEnvelopeBatchSubmission(String& PayloadType, String& ProcessingMode, String& PayloadID, String PayloadLength, String& TimeStamp, String& SenderID, String& ReceiverID, String& CORERuleVersion, String& CheckSum, String Payload, Byte[]& Payload1, String& ErrorCode, String& ErrorMessage) in  C:\Project\xxxWS\Service References\ESAR\Reference.cs:line 681
       at ESARWS.ESAR278Operations.BatchSubmission() in C:\Project\xxxxOperations.cs:line 102

    Friday, March 30, 2018 5:38 PM
  • Hi TeshLongBeach,

    When did you get this error, sending request or receiving response?

    To check whether this is specific to this attachment, if you make a test with Java WebService without the attachment function, will the .net client work to call and receive response?

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 2, 2018 6:04 AM
  • I get this error when I received the response back from the service.  If I don't send an attachment the service complains about not having an attachment.  

    Here is my updated write method:

    public override void WriteMessage(Message message, System.IO.Stream stream)
            {
                VerifyOperationContext();

                message.Properties.Encoder = this._InnerEncoder;

                byte[] Attachment = null;
                if (OperationContext.Current.OutgoingMessageProperties.ContainsKey(SwaEncoderConstants.AttachmentProperty))
                    Attachment = (byte[])OperationContext.Current.OutgoingMessageProperties[SwaEncoderConstants.AttachmentProperty];

                if (Attachment == null)
                {
                    _InnerEncoder.WriteMessage(message, stream);
                }
                else
                {
                    // Associate the contents to the mime-part
                    _SoapMimeContent.Content = Encoding.UTF8.GetBytes(message.GetBody<string>());
                    _AttachmentMimeContent.Content = (byte[])OperationContext.Current.OutgoingMessageProperties[SwaEncoderConstants.AttachmentProperty];

                    // Now create the message content for the stream
                    _MimeParser.SerializeMimeContent(_MyContent, stream);
                }
            }

    Now I'm getting this error:

    The incoming message was signed with a token which was different from what used to encrypt the body. This was not expected.

    Tuesday, April 3, 2018 10:39 PM
  • Hi TeshLongBeach,

    It seems this issue is related with reading the response. Did you receive the request at Java Service? Did the Fiddler return expected value?

    For custom Message Encoder, I think you should use ReadMessage instead of WriteMessage.

    >> The incoming message was signed with a token which was different from what used to encrypt the body. This was not expected.

    When did you get this error, sending request or receiving response?

    >> If I don't send an attachment the service complains about not having an attachment. 

    For narrow down this issue, I would suggest you add a new method in Java Service.

    In addition, could you capture the request which could call Java Web Service correctly? I suggest you compare the difference from the requests in C#.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 5, 2018 3:57 AM