我有一个将xml发布到Web服务的代码。这是
网络服务设计代码
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
}
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(Foo foo)
{
return "Hello World";
}
}
从控制台aps C#
调用Web服务class Program
{
static void Main(string[] args)
{
using (WebClient client = new WebClient())
{
client.Headers.Add("SOAPAction", "\"http://tempuri.org/HelloWorld\"");
client.Headers.Add("Content-Type", "text/xml; charset=utf-8");
var payload = @"<?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><HelloWorld xmlns=""http://tempuri.org/""><foo><Id>1</Id><Name>Bar</Name></foo></HelloWorld></soap:Body></soap:Envelope>";
var data = Encoding.UTF8.GetBytes(payload);
var result = client.UploadData("http://localhost:1475/Service1.asmx", data);
Console.WriteLine(Encoding.Default.GetString(result));
}
}
}
以上代码是否正常?
为什么人们说不在生产中使用上述代码......可能会出现什么样的安全问题?
指导我如何在不创建代理的情况下以安全的方式将xml发布到Web服务?感谢