我正在将 ajax 连接到 wcf 服务。但是继续获取方法是不允许的。调试了几天。我不明白。我只是在测试默认的 GetData(int value) 方法。
阿贾克斯:
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$.ajax({
type: "POST",
url: "http://localhost:19478/Service1.svc/GetData",
data: JSON.stringify({"value": "test"}),
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function (msg) {
alert(msg);
},
error: function (msg) {
alert("Failed");
}
});
function OnSuccessCall(response) {
alert(response);
}
function OnErrorCall(response) {
alert(response.status + " " + response.statusText);
}
</script>
网络配置:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceTest.Service1" behaviorConfiguration="myServiceBehavior">
<endpoint name="webHttpBinding"
address="" binding="webHttpBinding"
contract="WcfServiceTest.IService1"
behaviorConfiguration="webHttp"
>
</endpoint>
<endpoint name="mexHttpBinding"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
<behavior name="NewBehavior0">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
服务1:
[OperationContract]
[WebInvoke(Method="POST",
RequestFormat=WebMessageFormat.Json,
ResponseFormat=WebMessageFormat.Json)]
string GetData(String value);
服务1:
public string GetData(String value)
{
return string.Format("You entered: {0}", value);
}
上面什么都没有public class Service1 : IService1
。[ServiceContract]
上面有一个public interface IService1
。
我添加了很多东西,删除了很多东西..我不知道了。我怀疑它是我的 web.config 文件,我不明白那部分