此問題已經以類似方式在許多帖子中提出,但沒有可行的解決方案。使用jQuery.ajax將字符串傳遞給WCF服務端點(500)
在ManagerDiscountService
我的服務端點的樣子:
[ServiceBehavior]
[ServiceContract(Namespace = "Cart")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ManagerDiscountService : CartService
[OperationContract]
// also tried [WebInvoke(RequestFormat=WebMessageFormat.Json)]
// also tried [WebInvoke(RequestFormat=WebMessageFormat.Json, Method="POST")]
public MyObject ToggleMode(string userId, string pwd, string domain)
的web.config:
<service name="Cart.ManagerDiscountService">
<endpoint address="" behaviorConfiguration="Item.ItemAspNetAjaxBehavior"
binding="webHttpBinding" bindingConfiguration="wsSecureHttp"
contract="Cart.ManagerDiscountService" />
</service>
<!-- tried adding a similar wsHttp binding since the POST is not SSL, no luck -->
我嘗試後userId
,pwd
和domain
這個終點,但我看到的是500的。 爲什麼不公佈這項工作方式?當我在Chrome調試,error
總是在$.ajax
接下來執行:
params = { "userId": "user", "pwd": "password", "domain": "mydomain" };
$.ajax({
type: "POST",
url: "/Ajax/Cart/ManagerDiscountService.svc/ToggleMode",
dataType: "json",
data: JSON.stringify(params, null, null),
contentType: "application/json; charset=utf-8",
success: function (data) {
// ...
},
error: function() {
// ...
}
});
結合修正空參數來處理,我們在IE8中發現了一些問題。我也試過沒有null參數,沒有運氣。 –