| Web服务中的异常处理(2) |
|
作者:网络 文章来源:转载 点击数: 更新时间:2006-1-6 |
| [ 字体:缩小 正常 放大 | 双击自动滚屏 ] |
请选择合适的字体颜色:
|
|
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;
[1] |
|
| 文章录入:54iter 责任编辑:54iter |
上一篇文章: 用Profiler监测Web应用之三 下一篇文章: IE 代理服务器设置程序实现 |
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |