WCFService.cs
[AspNetCompatibilityRequirements(
RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class WCFService : IWCFService{
public Boolean insertUser(String name, String password)
{
Boolean successInsert = false;
XDocument xDoc = XDocument.Load("`http://localhost:57833/DataProvider/XML/User.xml`");
Boolean userExist = (from user in xDoc.Descendants("user")
where (String)user.Attribute("name") == name
select user).Any();
if (!userExist)
{
XElement root = xDoc.Root;
int lastUserId = Convert.ToInt16(root.Elements("user").Last().Attribute("id").Value);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("`http://localhost:57833/DataProvider/XML/User.xml`");
XmlNode xmlElementUser = xmlDoc.CreateNode(XmlNodeType.Element, "user", "");
XmlAttribute xmlAttributeUserID = xmlDoc.CreateAttribute("id");
XmlAttribute xmlAttributeName = xmlDoc.CreateAttribute("name");
XmlAttribute xmlAttributePassword = xmlDoc.CreateAttribute("password");
XmlAttribute xmlAttributeUserType = xmlDoc.CreateAttribute("userType");
xmlAttributeUserID.Value = (lastUserId + 1).ToString();
xmlAttributeName.Value = name;
xmlAttributePassword.Value = password;
xmlAttributeUserType.Value = "borrower";
xmlElementUser.Attributes.Append(xmlAttributeUserID);
xmlElementUser.Attributes.Append(xmlAttributeName);
xmlElementUser.Attributes.Append(xmlAttributePassword);
xmlElementUser.Attributes.Append(xmlAttributeUserType);
xmlDoc.DocumentElement.AppendChild(xmlElementUser);
xmlDoc.Save("`http://localhost:57833/DataProvider/XML/User.xml`");
successInsert = true;
}
return successInsert;
}
}
我正在做一个 windows phone 7 应用程序,我希望使用 WCF 从 XML 文件中检索并附加到 XML 文件。我遇到了“不支持 URI 格式”的错误。当我希望保存这行“xmlDoc.Save(” http://localhost:57833/DataProvider/XML/User.xml
“);”的 XML 时。似乎 WCF 无法在服务器中附加 XML 文件。