0

我是 WCF 世界的新手。我有一个包含 Web 应用程序的解决方案(它有对 WCF 服务应用程序的 JQuery Ajax 调用,这是解决方案中的另一个项目。经过 2 天的工作(破解)我处于能够传递请求并获得响应的状态在此处输入图像描述

但是在尝试显示警报时给了我 200 解析器错误。在此处输入图像描述

任何帮助将不胜感激

进一步参考

$.ajax({
                    async: true,
                    type: 'GET', //GET or POST or PUT or DELETE verb
                    url: 'http://localhost:61057/Service1.svc/GetCustomer', // Location of the service
                    dataType: 'jsonp', //Expected data format from server
                    success: function (data) {//On Successfull service call
                        ServiceSucceeded(data);
                    },
                    error: function () { ServiceFailed(Data); } // When Service call fails
                });

网页配置

  <system.serviceModel>
    <services>
      <service name="FIN.Services.Service1" behaviorConfiguration="DefaultBehavior">
        <endpoint address="http://localhost:61057/service1.svc" binding="webHttpBinding" contract="FIN.Services.IService1" behaviorConfiguration="AjaxBehavior">
          <identity>
            <dns value="locahost"/>
          </identity>
        </endpoint>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="webBinding">
          <security mode="None">
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DefaultBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="AjaxBehavior">
          <enableWebScript/>
        </behavior>

      </endpointBehaviors>

    </behaviors>
  </system.serviceModel>

服务接口:

[WebInvoke(ResponseFormat = WebMessageFormat.Json, Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json)]
        [OperationContract]
        string GetCustomer();
4

2 回答 2

0

您正在使用 jsonp,意味着您要调用跨域服务。对于跨域服务,您的网址应如下所示

http://localhost:61057/Service1.svc/GetCustomer?callback=?

你还必须在 web.config 中进行一些更改

查看以下链接以获取完整示例

在 wcf 中调用跨域服务

于 2012-06-05T18:52:12.730 回答
0

如果您不需要参数,请在您的 ajax 调用中添加以下内容..

数据: ”{}”,

于 2012-06-05T18:45:55.967 回答