简体   繁体   中英

Using a Wcf Service in web application

I created a Wcf Service Library. There are Service1 and IService1 class and interface in it.

Service:

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";
    }
}

Iservice:

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

I followed this article. After this i have added an another project and added Service reference there and add text file as named AjaxService.svc

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

But when i am running this file in the browser:

在此处输入图片说明

Thank god. I solved my problem:

I have just copied all files from Target folder and paste them to the Project.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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