我使用简单的webclient对象将12 +奇数Web服务集成到我的应用程序中。
我没有添加任何Web引用,只使用了WebClient.UploadData(url,byte []数据)。
我的请求构建如下。这是标准方法吗?
XDocument doc= new XDocument(
new XDocument(
new XDeclaration("1.0", "utf-8", String.Empty),
new XElement(soapenv + "Envelope",
new XAttribute(XNamespace.Xmlns + "soapenv", soapenv), new XAttribute(XNamespace.Xmlns + "get", get),
new XElement(soapenv + "Header"),
new XElement(soapenv + "Body",
new XElement(get + "GetRate",
new XElement("rtRequest",
new XElement(get + "account" + accountValue)
string xstring = doc.ToString();
byte[] Data = Encoding.UTF8.GetBytes(xstring);
response = client.UploadData(RatingUrl, Data);
答案 0 :(得分:1)
如果它是常规的SOAP服务,那么不,这不是首选方法。使用Web引用,它将基于WSDL为您生成代理类。它会更容易,更不容易出错,而且更易于维护。
答案 1 :(得分:1)
不,它不是标准方法。
在.NET世界中,Windows Communication Foundation是与SOAP服务交互的推荐框架。它包装了所有传输和消息格式的东西,因此您不必手动编码(如示例所示)。
使用Add Service Reference为您的服务生成适当的代理类。
这是一个introduction article,概述了WCF。