English 中文(简体)
Ajax WCF 休息服务呼叫返回空白页面
原标题:Ajax WCF Restful Service Call Return Blank Page

我试图通过使用jquery 的ajax 结构呼叫一个 wcf 休息服务, 但是在这样做时, 我收到来自jquery的错误请求。 另外, 我试图直接浏览服务并接收一个空白的页面。 我过去曾经打过WCF服务电话, 无法在这里找到什么是错的 。 感谢大家的事先回复。 当直接浏览服务时, 我看不到结果 。 这是拨打电话的 jquery ajax 代码 :

$.ajax({ type: "GET", dataType: "json", contentType: "application/json; charset=utf-8", url: "http://localhost:57452/mobile/WCFService/ContactService.svc/hello", success: function (result) { alert( success ); }, error: function (result) { 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>
问题回答

我找到了这个问题。 似乎在添加 wcf 服务时, 配置文件中添加的默认连接没有添加 WebHttpBinding 。 从此链接中找到了解决方案, < a href=" http://www.codeproject.com/ artes/132809/ Calling- WCF- Services- useing- jQuery" rel=“ nofollow” > http://www.codeproject. com/ arts/132809/ Calling- WCF- Services- useing- jQuery





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签