WCF方法的断点没有被击中

时间:2013-05-15 08:40:17

标签: wcf c#-4.0 query-string querystringparameter

我是WCF的新手,我正在构建一个服务来进行CRUD操作。我创建了一个带有两个参数的新void方法。我设置了一个断点,在调试模式下我粘贴了这个URL:

http://localhost:55152/WcfDataService.svc/AddNewNote()?ParamNoteTitle='dfdfdf'&ParamNoteText='dfdfdfdf'

这是我的代码:

 [WebGet]
    public void AddNewNote(string ParamNoteTitle, string ParamNoteText)
    {
        //My hardcoded values for now...
        int ParentID = 8879;
        int JobID = 1000088150;
        int ContactID = 309;
        Guid UserID = Guid.NewGuid();
        string RelatedType = "Advertiser Contact";
        bool IsShared = true;

        tblNote N = new tblNote
        {
          NotesTitle = ParamNoteTitle,
          NotesText = ParamNoteText,
          ParentID = ParentID,
          ContactID = ContactID,
          JobID = JobID,
          UserID = UserID,
          GroupID = null,
          RelatedType = RelatedType,
          IsShared = IsShared
        };
        this.CurrentDataSource.tblNotes.Add(N);
        this.CurrentDataSource.SaveChanges();

    }

我收到404错误。我的查询字符串/网址是否有问题?

2 个答案:

答案 0 :(得分:0)

首先,通过在浏览器中粘贴此URL来检查服务本身是否正常运行:

http://localhost:55152/WcfDataService.svc

如果是这样,我建议您查看类似的SO question

希望有所帮助!

答案 1 :(得分:0)

我最终将我的方法类型更改为IQueryable并调用方法以在插入后使用我的ID检索新行。我最初想要返回一个整数或bool,所以在我的Javascript中我可以通过查看返回值来处理成功或失败。

 [WebGet]
    public IQueryable<vw_Note> AddNewNote(string ParamNoteTitle, string ParamNoteText)
    {
        //My hardcoded values for now...
        int ParentID = 8879;
        int JobID = 1000088150;
        int ContactID = 309;
        Guid UserID = new Guid("8b0e303a-68aa-49a5-af95-d994e2bdd5ac");
        Guid NoteID = Guid.NewGuid();
        string RelatedType = "Advertiser Contact";
        bool IsShared = true;

        tblNote N = new tblNote
        {
            NotesID = NoteID,
            NotesTitle = ParamNoteTitle,
            NotesText = ParamNoteText,
            ParentID = ParentID,
            ContactID = ContactID,
            JobID = JobID,
            UserID = UserID,
            GroupID = null,
            RelatedType = RelatedType,
            IsShared = IsShared
        };
        try
        {
            this.CurrentDataSource.tblNotes.Add(N);
            this.CurrentDataSource.SaveChanges();
            return GetNoteByID(NoteID);

        }
        catch (Exception ex)
        {
            return GetNoteByID(NoteID);
        }

    }

如您所见,它将返回一组数据。我被困在如何处理使用WCF插入数据然后响应客户端请求,但我设法解决它。不管怎样,谢谢!