异常详情:
System.ServiceModel.Web.dll中出现'System.InvalidOperationException'类型的第一次机会异常 附加信息:不允许传入请求的HTTP方法'GET'(使用URI http://localhost:24342/Test.svc/DoWork?callback=jQuery110203769165082986856_1479380612393&testParameter=TEST&_=1479380612394)。
我使用的是Ajax嵌入式WCF服务。 WCF客户端是一个jQuery Ajax调用。我的代码:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceAspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="Service">
<endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="Service"/>
</service>
</services>
</system.serviceModel>
Web配置:
<script src="Scripts/jquery-1.9.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function CallMyService() {
$.support.cors = true;
var param = '{"testParameter": "TEST"}';
$.ajax({
url: 'http://localhost:24342/Test.svc/DoWork',
data: param,
type: "POST",
dataType: "jsonp",
contentType: "application/json",
success: ServiceSucceeded,
error: ServiceFailed
});
}
Ajax代码:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/a"
android:duration="1000"></item>
<item android:drawable="@drawable/b"
android:duration="1000"></item>
<item android:drawable="@drawable/c"
android:duration="1000"></item>
</animation-list>
答案 0 :(得分:0)
我能够通过使用Ajax嵌入式创建WCF服务来解决这个问题。