【问题标题】:WCF method's breakpoint not being hitWCF 方法的断点未命中
【发布时间】:2013-05-09 18:05:49
【问题描述】:

我是 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 错误。我的查询字符串/URL 有问题吗?

【问题讨论】:

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


    【解决方案1】:

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

    http://localhost:55152/WcfDataService.svc
    

    如果是这样,我建议你看看这个类似的 SO question

    希望有帮助!

    【讨论】:

    • Communal - Betc 我还有其他检索数据的方法,所以我知道根 URL 正在工作。我会看看你提供的链接。
    • 这里有更多链接可以帮助您:Link#1Link#2。如果它托管在 MVC 应用程序 Link#3Link#4
    【解决方案2】:

    我最终将我的方法类型更改为 IQueryable 并在插入后调用一个方法来检索带有我的 ID 的新行。我最初想返回一个整数或布尔值,所以在我的 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 处理插入数据然后响应客户端请求,但我设法解决了它。还是谢谢!

    【讨论】:

      猜你喜欢
      • 2011-10-18
      • 1970-01-01
      • 2011-12-01
      • 2010-10-13
      • 2019-03-29
      • 2012-11-01
      • 1970-01-01
      • 2019-10-02
      • 2017-10-16
      相关资源
      最近更新 更多