0

这个问题已经在许多帖子中以类似的方式提出,但没有可行的解决方案。

我的服务端点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)

网络配置:

<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() {
        // ...
    }
});
4

3 回答 3

1

我猜你只需要一个uri模板。我在这里编辑了你的代码:
[OperationContract]
[WebGet(UriTemplate="ToggleMode?userId={userId}&pwd={pwd}&domain="{domain}", ResponseFormat=WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]

where 方法看起来像:
MyObject ToggleMode(string userId, string pwd, string domain);

此外,您的 ajax 调用 url 看起来像:
url: "/Ajax/Cart/ManagerDiscountService.svc/ToggleMode?userId=uid&pwd=pwd&domain=domain",
然后您不需要在 ajax 调用中设置“数据”......看看这是否有效。

于 2012-11-01T10:54:28.413 回答
0

Try using code as follows:

params = { "userId": "user", "pwd": "password", "domain": "mydomain" };
$.ajax({
    type: "POST",
    url: "/Ajax/Cart/ManagerDiscountService.svc/ToggleMode",
    dataType: "json",
    data: JSON.stringify(params),
    contentType: "application/json; charset=utf-8",
    success: function (data) {
        // ...
    },
    error: function() {
        // ...
    }
});

also for what you are passing extra two null parameters to the contract.

于 2012-11-01T10:06:59.257 回答
0

::sigh:: 已通过将wsSecureHttp绑定替换为wsHttp

<endpoint address="" behaviorConfiguration="Item.ItemAspNetAjaxBehavior"
 binding="webHttpBinding" bindingConfiguration="wsHttp" 
 contract="Cart.ManagerDiscountService" />
于 2012-11-01T14:13:16.993 回答