In an ASP.NET application in which users ("User A") can set up their own web service connections using SOAP, I let them insert their own envelope, which, for example, could be something along these lines:
//Formatted for Clarity
string soapMessage =
"<soap: Envelope //StandardStuff>
<soap:Header //StandardStuff>
<wsse:UsernameToken>
<wsse: Username>{F1}</wsse:Username>
<wsse: Password Type''>{F2}</wsse:Password>
</wsse:UsernameToken>
</soap:Header>
<soap:Body>
<ref:GetStuff>
<ref:IsActive>{F3}</ref:IsActive>
</ref:GetStuff>
</soap:Body>
</soap:Envelope>"
At the same time I a "User B" that sends an array of data, passed down from Javascript as json that looks a little something like this:
[
{
key: "F1",
value: "A"
},
{
key: "F2",
value: "B"
},
{
key: "F3",
value: "C"
}
];
This array enters the fray as a string before being deserialized (dynamic JsonObject = JsonConvert.DeserializeObject(stringifiedJson);
).
Now, I would like to be able to insert the corresponding values into the envelope, preferably with a degree of security that won't allow people to do funky stuff by inserting weird values in the array (a regex would probably be my last resort).
So far I'm aware of the concept to build the string like so (With the {}
's in the soap message being replaced by {0}, {1} & {2}
):
string value1 = "A";
string value2 = "B";
string value3 = "C";
var body = string.Format(@soapMessage, value1, value2, value3);
request.ContentType = "application/soap+xml; charset=utf-8";
request.ContentLength = body.Length;
request.Accept = "text/xml";
request.GetRequestStream().Write(Encoding.UTF8.GetBytes(body), 0, body.Length);
But the amount of values in this array as well as the might change according to the user's input as well as a shifting order of references, so I need something more flexible. I'm very new to making SOAP calls, so as dumb an answer as possible would be appreciated.