【问题标题】:Ajax WCF Restful Service Call Return Blank PageAjax WCF Restful 服务调用返回空白页
【发布时间】:2012-05-25 21:11:17
【问题描述】:

我正在尝试使用 jquery 通过 ajax 构造调用 wcf 休息服务,但是从 jquery 执行此操作时出现错误的请求错误。此外,我尝试直接浏览到该服务并收到一个空白页面。我过去曾做过 WCF 服务调用,但无法弄清楚这里出了什么问题。提前感谢所有回复。直接浏览服务时,我看不到任何结果。这是进行调用的 jquery ajax 代码:

$.ajax({ 类型:“获取”, 数据类型:“json”, contentType: "应用程序/json; charset=utf-8", url: "http://localhost:57452/mobile/WCFService/ContactService.svc/hello", 成功:函数(结果){ 警报(“成功”); }, 错误:函数(结果){ alert(result.status + ' ' + result.statusText); }

    });

这里是服务接口:

[ServiceContract]
    public interface IContactService
    {
        [OperationContract]
        [WebGet(
            ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "hello")]
        string SaySomething();

    }

这里是服务类:

 [AspNetCompatibilityRequirements(RequirementsMode =      AspNetCompatibilityRequirementsMode.Allowed)]
    public class ContactService : IContactService
    {
        public string SaySomething()
        {
            // Add your operation implementation here
            return "Hello!";
        }
    }

这是 web.config 文件中服务的配置:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <behaviors>
      <serviceBehaviors>
        <behavior name="SomeNameSpace.mobile.WCFService.ContactServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="LeeCounty_ASP.mobile.WCFService.ContactServiceBehavior"
        name="SomeNameSpace.mobile.WCFService.ContactService">
        <endpoint address="" binding="wsHttpBinding" contract="SomeNameSpace.mobile.WCFService.IContactService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

【问题讨论】:

    标签: ajax wcf rest service


    【解决方案1】:

    我发现了问题。看来添加wcf服务时,配置文件中添加的默认绑定并没有添加webHttpBinding。从这个链接找到解决方案,http://www.codeproject.com/Articles/132809/Calling-WCF-Services-using-jQuery

    【讨论】:

    • 我有 webHttpBinding,但我仍然得到一个空白页。您是否采取了其他措施来解决此错误?我在同一个解决方案中有其他 REST 服务可以正常工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多