簡體   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