0
我想從角度發佈到WCF json服務端點,但在嘗試中失敗。我已經驗證該服務正在通過其他方式工作,併爲指定的URL工作。以角度發佈到WCF json端點
使用螢火蟲我可以看到該請求被輸出爲例如:
NetworkError: 400 Bad Request - http://www.myapi.com/V1/Service.svc/Authenticate?Password=password&UserName=username "
角代碼
app.service('UserService', function ($http) {
this.GetLoginStatus = function (AuthenticateRequest) {
$http({
url: APIURL + "/Authenticate",
method: "POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
params: AuthenticateRequest,
data: {
'Code': 'test data'
}
});
};
});
WCF Iservice
[WebInvoke(RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped)]
[OperationContract]
AuthenticateResponse Authenticate(AuthenticateRequest Request);
請求定義
[DataContract]
public class AuthenticateRequest
{
[DataMember]
public String UserName { get; set; }
[DataMember]
public String Password { get; set; }
}
你在哪裏設置/定義你的服務的基本認證?你確定auth字符串是好的?你使用郵遞員在鉻? – aet
我更新了我的代碼並刪除了該行。我確實使用郵遞員。 – CodeMilian
我對WCF並不是很熟悉,但不是用於添加XML元素的wrapped()樣式?如果意圖是讓api只說json,也許你不想要那個?另外,我不禁想到你可能想要在數據屬性中發送正文中的內容,而不是查詢參數(因爲服務期望POST)。 – aet