0

私は自分に POST リクエストを送信しようとしているので、WCF serviceできません。POST the service requestcan't get response.

私はWebHttpBindingを使用WCF service is hosted in Windows serviceしています。PORT 8181

WCF サービス メソッド:

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/{cstid}/{deptid}/get/customer/?cstname={cstname}", 
    BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json)]
Customer CustomerGet(string cstid, string deptid, string cstname);

JQuery POST メソッド

jQuery.ajax({
    type: 'POST',
    url: 'http://localhost:8181/mysite/e48/91/get/customer/?',
    dataType: 'json',
    contentType: "application/json; charset=utf-8",
    processData: false,
    success: function (data) {
        alert(data);  // not getting anything  :(
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert('Error :' + textStatus);
    }
});

このサービスを呼び出せない理由と、この問題の解決方法を教えてください。

前もって感謝します!

4

2 に答える 2

0

あなたの UriTemplate:

/{cstid}/{deptid}/get/customer/?cstname={cstname}

jQuery URL:

/e48/91/get/customer/?

が欠落しているように見えるcstnameため、クエリ文字列パラメーターは UriTemplate と一致する必要がないため、実行時の値は null になります。あなたの実装は表示されませんが、調べてみるCustomerとnullを受け入れていると思いますが、実際のインスタンスが見つからず、nullを返すだけです。

于 2011-06-24T14:36:48.513 に答える
0

あなたの UriTemplate は

 UriTemplate = "/{cstid}/{deptid}/get/customer/?cstname={cstname}",

少なくとも {cstname} のパラメーターを渡す必要があります。たとえば、これを試してください:

jQuery.ajax({
type: 'POST',
url: 'http://localhost:8181/mysite/e48/91/get/customer/?',
data: { cstname: "nunu" },
dataType: 'json',
contentType: "application/json; charset=utf-8",
processData: false,
success: function (data) {
    alert(data);  // not getting anything  :(
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
    alert('Error :' + textStatus);
}});

私の意見では、WebGet 操作以外の目的で WCF Web Http サービスを使用することは、価値があるよりも面倒です。

于 2011-06-25T03:46:57.803 に答える