Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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
C# REST Post请求给出未找到端点错误_C#_Wcf_Rest - Fatal编程技术网

C# REST Post请求给出未找到端点错误

C# REST Post请求给出未找到端点错误,c#,wcf,rest,C#,Wcf,Rest,我的配置文件看起来像 [OperationContract] [WebInvoke(Method="POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, UriTemplate= "SignIn/Username/{Username}/Password/{Password}", Req

我的配置文件看起来像

[OperationContract]
[WebInvoke(Method="POST", 
           BodyStyle = WebMessageBodyStyle.Wrapped,
           ResponseFormat = WebMessageFormat.Json,
           UriTemplate= "SignIn/Username/{Username}/Password/{Password}",
           RequestFormat= WebMessageFormat.Json)]

 string SignIn(string Username,string Password);

[OperationContract]
[WebInvoke(Method="POST", 
           BodyStyle = WebMessageBodyStyle.Wrapped,
           ResponseFormat = WebMessageFormat.Json,
           UriTemplate= "SignIn/Username/{Username}/Password/{Password}",
           RequestFormat= WebMessageFormat.Json)]

 string SignIn(string Username,string Password);
但当我将URL和请求体分开时,它会给我未找到的端点

[OperationContract]
[WebInvoke(Method="POST", 
           BodyStyle = WebMessageBodyStyle.Wrapped,
           ResponseFormat = WebMessageFormat.Json,
           UriTemplate= "SignIn/Username/{Username}/Password/{Password}",
           RequestFormat= WebMessageFormat.Json)]

 string SignIn(string Username,string Password);
类似URL:

[OperationContract]
[WebInvoke(Method="POST", 
           BodyStyle = WebMessageBodyStyle.Wrapped,
           ResponseFormat = WebMessageFormat.Json,
           UriTemplate= "SignIn/Username/{Username}/Password/{Password}",
           RequestFormat= WebMessageFormat.Json)]

 string SignIn(string Username,string Password);
正文:sign/Username/guru/Password/122

[OperationContract]
[WebInvoke(Method="POST", 
           BodyStyle = WebMessageBodyStyle.Wrapped,
           ResponseFormat = WebMessageFormat.Json,
           UriTemplate= "SignIn/Username/{Username}/Password/{Password}",
           RequestFormat= WebMessageFormat.Json)]

 string SignIn(string Username,string Password);

有什么建议吗?

因为您的
WebInvoke
属性指定了一个
UriTemplate
,以post方式发送的数据不再与模板匹配,这将导致“未找到端点”错误

[OperationContract]
[WebInvoke(Method="POST", 
           BodyStyle = WebMessageBodyStyle.Wrapped,
           ResponseFormat = WebMessageFormat.Json,
           UriTemplate= "SignIn/Username/{Username}/Password/{Password}",
           RequestFormat= WebMessageFormat.Json)]

 string SignIn(string Username,string Password);

此外,您的请求是httphttps,但您只有httpaddress前缀。在
->

中添加https地址非常感谢,如果我希望参数位于请求正文中,如何设置URI模板??由于登录信息是真实的数据,我不希望暴露任何建议??首先,完全删除该模板。之后,您将在post正文中将数据指定为{UserName:“UserName”,Pasword:“password”}。它应该是JSON,因为您已将
RequestFormat
设置为
WebMessageFormat.JSON
。感谢您提供了正确的方向。我删除了URI,当我发送{Username:“guru”,Password:“1234”}作为我的请求主体时,它抛出了一个错误,服务器在处理请求时遇到了一个错误。异常消息为“令牌”,但应为“U”。有关详细信息,请参阅服务器日志。异常堆栈跟踪为:System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader,String res,String arg1,String arg2,String arg3)的System.Xml.XmlExceptionHelper.ThrowTokenExpected(XmlDictionaryReader阅读器,需要字符串,Char found谢谢大家。我已经解决了。格式为{“用户名”:“guru”,“密码”:“1234”}:)
[OperationContract]
[WebInvoke(Method="POST", 
           BodyStyle = WebMessageBodyStyle.Wrapped,
           ResponseFormat = WebMessageFormat.Json,
           UriTemplate= "SignIn/Username/{Username}/Password/{Password}",
           RequestFormat= WebMessageFormat.Json)]

 string SignIn(string Username,string Password);