none
Read "application/soap+xml;charset=utf-8" from service RRS feed

  • Question

  • Hi,

    I am send soap message to WCF service using following code

    WebClient myWebClient = new WebClient();
    myWebClient.Headers.Add("Content-Type", "application/soap+xml;charset=utf-8");
    byte[] byteArray = Encoding.ASCII.GetBytes(xml);
    byte[] responseArray = myWebClient.UploadData("http://localhost:5447/MyService", "POST", byteArray);

    But when I try receive the message in WCF service using following code , I am getting binary format , i don't how to read the soap xml which I sent from client.

    Message SoapMessage = OperationContext.Current.RequestContext.RequestMessage;
    string strMsg = SoapMessage.ToString();

    Can any one please help me.

    regards
    Prince


    Regards Prince

    Wednesday, April 16, 2014 4:29 AM

Answers

  • Hi Prince,

    Based on your description, to read the raw soap message sent from client, you can custom a server side message inspector which implements IDispatchMessageInspector interface; in AfterReceiveRequest method create a copy of the message instance, using the CreateBufferedCopy() method, and write it using the ToString() of the Message type. A Sample from this blog:

    public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
            request = buffer.CreateMessage();
            Console.WriteLine("Received:\n{0}", buffer.CreateMessage().ToString());
            return null;
        }
    

    You can also foreach message headers in this method, using:

     Message originalMessage = buffer.CreateMessage();
            foreach (MessageHeader h in originalMessage.Headers)
            {
                Console.WriteLine("\n{0}\n", h);
            }
    Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 17, 2014 2:02 AM
    Moderator

All replies

  • Hi Prince,

    Based on your description, to read the raw soap message sent from client, you can custom a server side message inspector which implements IDispatchMessageInspector interface; in AfterReceiveRequest method create a copy of the message instance, using the CreateBufferedCopy() method, and write it using the ToString() of the Message type. A Sample from this blog:

    public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
            request = buffer.CreateMessage();
            Console.WriteLine("Received:\n{0}", buffer.CreateMessage().ToString());
            return null;
        }
    

    You can also foreach message headers in this method, using:

     Message originalMessage = buffer.CreateMessage();
            foreach (MessageHeader h in originalMessage.Headers)
            {
                Console.WriteLine("\n{0}\n", h);
            }
    Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 17, 2014 2:02 AM
    Moderator
  • Haixia Xie,

    Thank you very much


    Regards Prince

    Wednesday, April 23, 2014 3:50 AM