【发布时间】:2011-04-08 02:43:09
【问题描述】:
我已经设置了一个 wcf 服务。不幸的是,当我通过提琴手、网络或其他任何地方调用该服务时,我得到一个 http 400 错误。我真的很困惑从哪里开始解决这个问题。任何建议表示赞赏。 WSDL 目前不是一个选项。 REST 是一项要求。我之前可以使用 GET 进行调用,但是,get 并不安全,因为我需要传递用户 ID 和密码才能进行验证,而且很容易查看。
wcf服务有如下接口:
[WebInvoke(UriTemplate = "/Login", Method="POST",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped)]
[OperationContract]
bool Login(string UserName, string PassWord, string AppKey);
该服务具有以下代码。是的,这段代码是不完整的,我知道 AppKey 真的没有做任何事情,它在这一点上作为一个占位符。
public bool Login(string UserName, string PassWord, string AppKey)
{
bool bl = false;
if (String.IsNullOrEmpty(AppKey))
{
throw (new ApplicationException(AppKeyNull));
}
if (Membership.ValidateUser(UserName, PassWord))
{
bl = true;
}
return (bl);
}
我正在尝试通过提琴手调用该服务。我有以下网址:
http://127.0.0.1:82/WebServices/RemoteAPI.svc/Login
我有以下标题设置:
User-Agent: Fiddler
Host: 127.0.0.1:82
Content-Length: 46
Content-Type: application/x-www-form-urlencoded
我有以下身体设置:
UserName=xxxxxx&PassWord=yyyyyy&AppKey=blah
【问题讨论】: