由ajax调用wcf服务时出错

时间:2014-12-16 13:01:42

标签: javascript c# jquery ajax wcf

我想在html页面中使用ajax运行这个简单的wcf方法作为测试,但它根本没有运行而且idont知道问题是什么

![错误讯息] [1]

IcustomerService页面

  

[OperationContract的]           [WebInvoke(Method =" POST",ResponseFormat = WebMessageFormat.Json)]            string GetTEST();

service.svc page

[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);
>                     }
>                 });
>             }
> 
> 
&#13;
&#13;
&#13;

这是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>  
     

                       

     

1 个答案:

答案 0 :(得分:0)

网址是否正确?我认为端口可能已经改变了。 IIS中的主机服务然后尝试。