通过 ajax 调用 wcf 服务时出错
Error calling wcf service by ajax
我在html页面中使用ajax作为测试运行这个简单的WCF方法,但它根本没有运行,我不知道问题是什么
![错误信息][1]
客户服务页面
[经营合同] [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 中托管服务,然后尝试。
相关文章:
- 使用ajax将数据发布到asmx web服务并使用javascript函数在html页面中编写响应时出错
- 尝试将 AngularJS 服务用作构造函数时出错
- 通过 ajax 调用 wcf 服务时出错
- 尝试在 AngularJS 上对基本服务进行单元测试时出错
- "访问控制允许原点不允许原点为null"使用jQuery调用web服务时出错
- 联机运行web服务时出错
- Ember通知出错可以't读取属性“t”;“服务”;的未定义
- 尝试使用javascript使用Mashape Web服务时出错
- 通过Javascript创建服务活动时出错
- 在控制器中注入服务时出错
- 在Azure node.js应用程序服务中使用LevelDB时出错
- Chrome浏览器在angular web应用中刷新grunt服务时出错
- 执行依赖AWS cognito的angularjs服务的单元测试时出错
- AngularJS + NodeJS -调用注入服务时出错
- AngularJS:在工厂服务中添加$scope时出错
- 运行“Grunt服务”时出错.使用generator-angular-fullstack种子
- 从typescript调用Web服务时出错
- 使用示例服务在控制器之间传递数据时出错
- 将服务放在不同的js文件中时出错
- 英特尔XDK -尝试从“探索服务”面板中使用Web服务时出错