0

I have a SOAP message that is built dynamically using various XmlDocument.CreateElement and AppendChild method calls. This soap message comes out looking like this:

var message="<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">
<SOAP:Body>
<m:EDI  
ID=\"ConfigurationName={f0dc2db2-0431-4c31-ba8b-053a33f3899f}\" 
Frequency =\"8\" xmlns:m\"http://www.foo/schemas/\">
<Totes><Tote   
    a=\"\" 
    b=\"123\" 
    c=\"Stati\" 
    d=\"T8b52830b-fe69-4\" 
    e=\"M0056122648\" 
    f=\"Route\" 
    g=\"\" 
    h=\"1/1/0001 12:00:00 AM\" />
</Totes>
</m:EDI></SOAP:Body></SOAP:Envelope>";

Now, I wish to POST this to an MS MVC action, but I don't know what signature to use or how to post it. I tried this and it worked, but the rawSoapMessage argument was null in the action:

var messageBytes = Encoding.UTF8.GetBytes(message); 
var webRequest = (HttpWebRequest) WebRequest.Create(url);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
webRequest.ContentLength = messageBytes.Count();

using (var s = webRequest.GetRequestStream())
{
     s.Write(messageBytes, 0, messageBytes.Length);
     s.Close();
}

var webResponse = (HttpWebResponse) webRequest.GetResponse();

And here is the controller action I am trying to POST to:

public string ReceiveManifest([FromBody] string rawSoapMessage)
{
    return rawSoapMessage
}

Removing "[FromBody]" produces a 404.

Thank you.

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

All you need is to add a WCF service endpoint (.svc file) to your current web project.

ali
  • 182
  • 2
  • 2
  • 10