使用WCF处理XML文档

时间:2014-06-02 06:45:25

标签: c# xml wcf

我创建了一个WCFService Library,我想在其中插入并从XML获取数据。

我的服务:

using System.ServiceModel;
namespace WcfServiceLibrary1{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        void InsertData(string Name, string Email, string Message);
    }   
}

我的服务类:

using System.Web;
using System.Xml.Linq; 
namespace WcfServiceLibrary1{
public class Service1 : IService1
{
    public void InsertData(string Name, string Email, string Message)
    {
        XDocument xmldoc = XDocument.Load(HttpContext.Current.Server.MapPath("DataFile.xml"));
        xmldoc.Element("root").Add(
            new XElement("User",
                new XAttribute("Name", Name),
                new XAttribute("Email", Email),
                new XAttribute("Message", Message)));
        xmldoc.Save(HttpContext.Current.Server.MapPath("DataFile.xml"));
    }
} 
}

我对WCF很新。当我运行它并调用我的insert()时,会出现以下异常:

enter image description here

1 个答案:

答案 0 :(得分:1)

为什么不包括MessageLogging和Tracing,看看会发生什么?