位置于:书籍教程首页>>服务器类>>web服务器>>正文

Web服务中的异常处理(2)

http://www.xp163.com/制作:   Web服务的实现
  
  为了达到这个示例的目的,我们创建一个名为CategoriesService的Web服务,选择一个可视化的C#ASP.netWeb服务作为项目的模版。一旦创建项目,我们就添加一个名为AddCategories的方法,并且给这个方法添加下列代码:

  [WebMethod]

  publicboolAddCategories(stringXML)

  {

  try

  {

  using(SqlConnectionconn=newSqlConnection())

  {

  if(ValidateXml(xml))

  {

  XmlDocumentdoc=newXmlDocument();

  doc.LoadXml(xml);

  conn.ConnectionString=

  "server=localhost;uid=sa;pwd=thiru;database=northwind";

  conn.Open();

  XmlNamespaceManagernsManager=new

  XmlNamespaceManager(doc.NameTable);

  //AddthenamespacetotheNamespaceManager
  
  nsManager.AddNamespace("catNS",
  
  "http://tempuri.org/CategoriesNamespace");
  
  XmlNodecategoryNode=
  
  doc.DocumentElement.SelectSingleNode("catNS:Category",
  
  nsManager);
  
  stringcategoryName=
  
  categoryNode.SelectSingleNode("catNS:CategoryName",
  
  nsManager).InnerText;
  
  stringcategoryDescription=
  
  categoryNode.SelectSingleNode("catNS:CategoryDescription",
  
  nsManager).InnerText;
  
  SqlCommandcommand=new
  
  SqlCommand("usp_InsertCategories",conn);
  
  command.CommandType=CommandType.StoredProcedure;
  
 最新网站更新
 网站Web服务中的异常处理(2)说明

 

 书籍教程站内推荐信息
 书籍教程网站地图