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)

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このエンドポイントに投稿しようとpwddomainていますが、表示されるのは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)]

メソッドは次のようになります。
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

次のようにコードを使用してみてください。

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

また、追加の2つのnullパラメーターをコントラクトに渡す場合にも使用します。

于 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 に答える