繁体   English   中英

通过Ajax调用WCF服务时出错

[英]Error calling wcf service by ajax

我想使用html页面中的ajax作为测试运行此简单的wcf方法,但是它根本无法运行,并且idont知道出了什么问题

![错误消息] [1]

IcustomerService页面

[OperationContract] [WebInvoke(Method =“ POST”,ResponseFormat = WebMessageFormat.Json)]字符串GetTEST();

service.svc页面

 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class Service1 : IcustomerService { public string GetTEST() { return "OKKKKKKKK"; } 

这是我的html页面

 > > <title></title> > <script type="text/javascript"></script> > <script type="text/javascript"src="Scripts/jquery-2.1.1.min.js"></script> > <script type="text/javascript" src="Scripts/jquery-2.1.1.intellisense.js"></script> > <script type="text/javascript" src="Scripts/jquery-2.1.1.js"></script> > <script type="text/javascript" src="Scripts/jquery.unobtrusive-ajax.js"></script> > <script type="text/javascript" src="Scripts/jquery.unobtrusive-ajax.min.js"></script> > > > <script type="text/javascript"> > var url = 'http://localhost:43315/Service1.svc/' > > function GetProducts() { > > var response; > > $.ajax({ > async: true, > type: 'post', > url: url + 'GetTEST', > contentType: 'application/json; charset=utf-8', > dataType: 'json', > success: function () { > alert("yahooooooooo"); > }, > > error: function (e) { > alert("Error : " + e.statusText); > } > }); > } > > 

这是web.config页面

  <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="Service1Behavior"> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="WebBehavior"> <enableWebScript/> </behavior> </endpointBehaviors> </behaviors> <services> <service behaviorConfiguration="Service1Behavior" name="WcfService1.Service1"> <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" /> <endpoint address="Web" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="WebBehavior" /> </service> </services> <protocolMapping> <add binding="basicHttpsBinding" scheme="https" /> </protocolMapping> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> 

网址正确吗? 我认为端口可能已更改。 然后在IIS中托管服务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM