我在不使用Xamarin Android中的wsdl和代理而调用SOAP Web服务。我想从我的edittext中传递用户名和密码作为XML文件中的参数。
这是我的代码:
public void Execute()
{
HttpWebRequest request = CreateWebRequest();
XmlDocument soapenvelopxml = new XmlDocument();
soapenvelopxml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ctrm=""http://CTRMService/CTRM"" xmlns:dtom=""http://schemas.datacontract.org/2004/07/DTOModelLayer.DataContracts"">
<soapenv:Header>
<DataHeader xmlns='http://CTRMService/CTRM'>AuthenticateUser</DataHeader>
</soapenv:Header>
<soap:Body>
<ctrm:AuthenticateUser>
<ctrm:request>
<dtom:Password></dtom:Password>
<dtom:Username></dtom:Username>
</ctrm:request>
</ctrm:AuthenticateUser>
</soapenv:Body>
</soapenv:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapenvelopxml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapresult = rd.ReadToEnd();
}
}
}
我想在<dtom:Password>
和<dtom:Username>
代码之间传递我的用户名和密码编辑文字中的文字。
答案 0 :(得分:0)
string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
...
<dtom:Username>@username</dtom:Username>
...
xml = xml.Replace("@username", usertext);
soapenvelopxml.LoadXml(xml);