WCF奇怪的行为

我在使用Web服务时得到了这个:

合同’IServices’的操作’Login’指定要序列化的多个请求体参数,而不包含任何包装元素。 最多可以在没有包装元素的情况下序列化一个body参数。 删除额外的body参数或将WebGetAttribute / WebInvokeAttribute上的BodyStyle属性设置为Wrapped。

我使用界面看起来像:

namespace DreamServices { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together. [ServiceContract] public interface IServices { [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "LogIn/{username}/{password}")] string Login(string username, string password); [OperationContract] [WebInvoke( Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "WaletTotalAmount/{userid}")] double? WaletTotalAmount(string userid); [OperationContract] [WebInvoke( Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "UserService/{userid}")] IList UserService(string userid); [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "InsertUpdateWallet/{userid}/{Amount}/{ComissionAmount}")] void InsertUpdateWallet(string userid, string Amount, string ComissionAmount); } } 

然后我主持它然后我添加web引用到我的网站并修改web.config,这样就好了

                              

知道如何修复此错误吗?

首先我不确定你为什么要使用GET操作登录,你应该使用POST吗? 接下来,您在UriTemplate定义了两个参数,但该方法只包含一个参数。 我建议你使用一个类作为参数,而不是返回字符串,你也可以返回一个模型。

 public class LoginModel { public string username { get; set; } public string password { get; set; } } public class Result { public bool success { get; set; } public string error { get; set; } } [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/LogIn")] public Result login(LoginModel loginModel)