通过 ajax 调用 wcf 服务时出错

Error calling wcf service by ajax

本文关键字:出错 服务 wcf ajax 调用 通过      更新时间:2023-09-26

我在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 中托管服务,然后尝试。