我在使用wcf服务时遇到问题.ajax中的响应是错误功能。网址完全正确。
$.ajax({
type: "post",
url: "http://192.168.1.3:16150/ajaxnewclinicalhost/Service.svc/gettablejson1",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg);
},
error: function () {
alert("error");
}
});
的Web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0">
<assemblies>
<add assembly="System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /></assemblies></compilation>
</system.web>
<system.serviceModel>
<services>
<service name="newclinicallibrary.Service1">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="" behaviorConfiguration="WEB" contract="newclinicallibrary.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WEB">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
答案 0 :(得分:1)
每当进行AJAX调用时,您应该记住,出于安全原因,浏览器只允许对与页面本身位于同一域的URL进行请求。因此,除非您的页面是从http://192.168.1.3提供的,否则您将无法对WCF服务进行AJAX调用。
如果情况确实如此,您可以尝试以下方法之一: