考えられるほぼすべてのことを試しましたが、WCF サービスへの ajax 呼び出しでまだ問題が発生しています。
私のWCFサービスには、以下のようなメソッドがあります:
//[WebInvoke(ResponseFormat = WebMessageFormat.Json, Method = "POST")]
[WebGet]
public string Test(int value)
{
return string.Format("You entered: {0}", value);
}
Patrick Thomas が Twitter で述べたように、私も[WebGet(BodyStyle = WebMessageBodyStyle.Wrapped)]
and[WebGet(BodyStyle = WebMessageBodyStyle.WrappedResponse)]
を使用してみましたが、うまくいきませんでした。
そして、次のような構成:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RestEndpoint">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="NoSecurityRestBinding" crossDomainScriptAccessEnabled="true">
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="WebServices.TestService">
<endpoint address="" binding="webHttpBinding" contract="WebServices.ITestService" bindingConfiguration="NoSecurityRestBinding" behaviorConfiguration="RestEndpoint" />
</service>
</services>
</system.serviceModel>
サービスは別のドメインにあるため、データを JSONP としてフォーマットしています。
$.ajax({
cache: false,
async: true,
type: "GET", // Was "POST"
dataType: "jsonp",
url: "http://mydomain.com/TestService.svc/Test?callback=?",
data: dataToPost,
contentType: "application/json;charset=utf-8",
success: function (msg) {
var testMsg = JSON.parse(msg);
var status = testMsg.TestResult;
alert(status);
},
error: function (msg) {
alert('Please email Jason with this exception: ' + msg.statusText);
}
});
そして、私は得ています:
「パーサーエラー」
「jQuery16408722478272714725_1332817261195 は呼び出されませんでした」
何が間違っている可能性がありますか?すべての WCF バイナリが 4.0 であることを確認しました。
よろしくお願いします。