【发布时间】:2013-07-28 21:37:01
【问题描述】:
我遇到了这个错误:
Operation 'Login' in contract 'Medicall' has a query variable named 'objLogin' of type 'Medicall_WCF.Medicall+clsLogin', but type 'Medicall_WCF.Medicall+clsLogin' is not convertible by 'QueryStringConverter'. Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter'.
我正在尝试将参数传递给我的 WCF 服务,但该服务甚至没有显示。
#region Methods
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public Int32 Login(clsLogin objLogin)
{
try
{
// TODO: Database query.
if (objLogin.username == "" & objLogin.password == "")
return 1;
else
return 0;
}
catch (Exception e)
{
// TODO: Handle exception error codes.
return -1;
}
}
#endregion
#region Classes
[DataContract(), KnownType(typeof(clsLogin))]
public class clsLogin
{
public string username;
public string password;
}
#endregion
我正在使用这个:
$.ajax({
url: "PATH_TO_SERVICE",
dataType: "jsonp",
type: 'post',
data: { 'objLogin': null },
crossDomain: true,
success: function (data) {
// TODO: Say hi to the user.
// TODO: Make the menu visible.
// TODO: Go to the home page.
alert(JSON.stringify(data));
},
failure: function (data) { app.showNotification('Lo sentimos, ha ocurrido un error.'); }
});
为了调用该服务,它之前使用了一个接收 1 个字符串参数的服务。 我怎样才能收到这个对象?
【问题讨论】:
-
是的,我有一个类似的服务工作,但它只收到 1 个字符串参数,为此我需要它来接收一个对象。这是我用来称呼它的语法(编辑了第一篇文章)。
标签: c# javascript .net wcf