繁体   English   中英

在Web应用程序中使用Wcf服务

[英]Using a Wcf Service in web application

我创建了Wcf服务库。 其中有Service1和IService1类和接口。

服务:

public class Service1 : IService1
{
    public string InsertData(string Name, string Email, string Message)
    {
        XDocument xDoc = XDocument.Load(HttpContext.Current.Server.MapPath("DataFile.xml"));
        xDoc.Element("Users").Add(
           new XElement("User",
                new XAttribute("Name", Name),
                new XAttribute("Email", Email),
                new XAttribute("Message", Message)));
        xDoc.Save(HttpContext.Current.Server.MapPath("DataFile.xml"));
        return "Registered Successfully";
    }
}

服务:

[ServiceContract]
public interface IService1
{
    [OperationContract]
    string InsertData(string Name, string Email, string Message);
}   

我关注了这篇文章。 此后,我添加了另一个项目并在其中添加了Service引用,并添加了名为AjaxService.svc的文本文件。

<%@ ServiceHost Debug="true" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" Language="C#" Service="DataServices.Service1" %>

但是,当我在浏览器中运行此文件时:

在此处输入图片说明

感谢上帝。 我解决了我的问题:

我刚刚从Target文件夹复制了所有文件,并将它们粘贴到Project中。

copy "$(TargetDir)*.dll" "$(ProjectDir)bin"
copy "$(TargetDir)*.pdb" "$(ProjectDir)bin"
copy "$(TargetDir)*.config" "$(ProjectDir)bin"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM