Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF方法';未命中断点_Wcf_C# 4.0_Query String_Querystringparameter - Fatal编程技术网

WCF方法';未命中断点

WCF方法';未命中断点,wcf,c#-4.0,query-string,querystringparameter,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,

我是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有问题吗?

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

http://localhost:55152/WcfDataService.svc
如果是这样的话,我建议你看看这个类似的so


希望有帮助

最后,我将我的方法类型更改为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);
        }

    }
[WebGet]
public IQueryable AddNewNote(字符串ParamNoteTitle,字符串ParamNoteText)
{
//我现在的硬编码值。。。
int ParentID=8879;
int JobID=1000088150;
int ContactID=309;
Guid UserID=新Guid(“8b0e303a-68aa-49a5-af95-d994e2bdd5ac”);
Guid NoteID=Guid.NewGuid();
string RelatedType=“广告客户联系人”;
bool-IsShared=true;
tblNote N=新tblNote
{
NotesID=NoteID,
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();
返回GetNoteByID(NoteID);
}
捕获(例外情况除外)
{
返回GetNoteByID(NoteID);
}
}

如您所见,它将返回一组数据。我一直在研究如何使用WCF插入数据,然后响应客户机请求,但我设法解决了这个问题。无论如何谢谢你

Communial-Betc我有其他检索数据的方法,因此我知道根URL正在工作。我将查看您提供的链接。这里有更多帮助您的链接:。如果它托管在MVC应用程序中