通过IClientMessageFormatter发送自定义消息 [英] Sending Custom Message through IClientMessageFormatter

查看:101
本文介绍了通过IClientMessageFormatter发送自定义消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我们正在尝试使用IClientMessageFormatter发送自定义SOAP消息.我们将重写OnWriteStartBody方法,以创建带有前缀的自定义XML主体标签.

We are trying to send a custom SOAP message by using IClientMessageFormatter. We are overriding the OnWriteStartBody method to create custom XML body tags with prefixes.

自定义消息是在IClientMessageFormatter的SerlializeRequest方法中创建的.

The custom message is created in the SerlializeRequest method of IClientMessageFormatter.

public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            Message message = this.formatter.SerializeRequest(messageVersion, parameters);
            return new CustomMessage(message);
        }

使用此自定义消息时,在SOAP主体中,在结束标记之前引入了一个省略号(...).即使没有在CustomMessage对象中添加任何自定义内容,也存在省略号.如果使用,则SerializeRequest中的默认Message省略号 不存在.感谢您对删除省略号的任何帮助.

Use of this custom message introduces an Ellipsis (...) in the SOAP body just before the closing tag. The ellipsis is present even without adding any custom content in the CustomMessage object. If we use, the default Message in SerializeRequest, ellipsis is not present. Any help on removing the ellipsis is appreciated.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://action url</Action>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">...</s:Body>
</s:Envelope>


推荐答案

史瑞克2

根据您的描述,您似乎想要替换省略号以在邮件正文中将其清空.如果是这样,您可以使用以下方法来实现它.

According to your description, it seems that you want to replace ellipsis to empty on your message body. If so, you could use the following method to achieve it.

public Message ChangeString(Message oldMessage, string from, string to)

        {

            MemoryStream ms = new MemoryStream();

            XmlWriter xw = XmlWriter.Create(ms);

            oldMessage.WriteMessage(xw);

            xw.Flush();

            string body = Encoding.UTF8.GetString(ms.ToArray());

            xw.Close();


            body = body.Replace(from, to);


            ms = new MemoryStream(Encoding.UTF8.GetBytes(body));

            XmlDictionaryReader xdr = XmlDictionaryReader.CreateTextReader(ms, new XmlDictionaryReaderQuotas());

            Message newMessage = Message.CreateMessage(xdr, int.MaxValue, oldMessage.Version);

            newMessage.Properties.CopyProperties(oldMessage.Properties);

            return newMessage;

        } 

用法:

public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)

        {

            Message message = this.formatter.SerializeRequest(messageVersion, parameters);

            return new ChangeString(message, "...", "");

        }

最诚挚的问候,

吴可乐


这篇关于通过IClientMessageFormatter发送自定义消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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