They said on prem and CSOM. None of the answers here are what he asked.
Here are some methods that do what we need:
HttpWebRequest CreateSoapWebRequest() {
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(adminUrl + "/_vti_adm/Admin.asmx");
webRequest.Headers.Add("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/CreateSite");
webRequest.ContentType = "text/xml; charset=\"utf-8\"";
webRequest.Method = "POST";
webRequest.Credentials = new NetworkCredential(username, password);
return webRequest;
}
XmlDocument CreateSoapEnvelope(string url, string title, string description, string user, string lcid, string webTemplate) {
XmlDocument soapEnvelopeDocument = new XmlDocument();
string soapEnv = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<CreateSite xmlns=""http://schemas.microsoft.com/sharepoint/soap/"">
<Url>{0}</Url>
<Title>{1}</Title>
<Description>{2}</Description>
<Lcid>{3}</Lcid>
<WebTemplate>{4}</WebTemplate>
<OwnerLogin>{5}</OwnerLogin>
<OwnerName>{6}</OwnerName>
<OwnerEmail/>
<PortalUrl/>
<PortalName/>
</CreateSite>
</soap:Body>
</soap:Envelope>", url, title, description, lcid, webTemplate, user, user);
Console.WriteLine("Create site collection soap request: {0}", soapEnv);
soapEnvelopeDocument.LoadXml(soapEnv);
return soapEnvelopeDocument;
}
void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest) {
using (Stream stream = webRequest.GetRequestStream()) {
soapEnvelopeXml.Save(stream);
}
}
And you can use the code like this:
XmlDocument soapEnvelopeXml = CreateSoapEnvelope(
yourUrl,
yourTitle,
yourDescription,
yourUser,
yourLcid,
yourWebTemplate
);
HttpWebRequest webRequest = CreateSoapWebRequest();
InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
asyncResult.AsyncWaitHandle.WaitOne();
using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) {
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream())) {
Console.WriteLine(rd.ReadToEnd());
}
}