注册 | 登录

解决 - How do you consume a RESTful WCF service from an ASP project using a service reference?

itPublisher 分享于



推荐:ASP.NET MVC提交一个较复杂对象至WCF Service

前一篇《jQuery.Ajax()执行WCF Service的方法》 我们有练习在 mvc应用程序中,POST 数据去wcf service并执

I am developing a RESTful WCF service which I then want to consume from a separate Project.

Is it possible to use a service reference from within the ASP project to consume the service using REST or are all service references treated as SOAP?

There are plenty of examples of using a service library as a service reference or consuming a REST service using the WCF starter toolkit using HttpClient but I've not found one that does what I was hoping to do.

Below is an extract from the ASP.Net web.config file that gets auto generated when the service reference is added. As you can see it mentions SOAP.

    <binding name="WebHttpBinding_IDataCaptureService">
     <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
      messageVersion="Soap12" writeEncoding="utf-8">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
       maxBytesPerRead="4096" maxNameTableCharCount="16384" />
   <endpoint binding="customBinding" bindingConfiguration="WebHttpBinding_IDataCaptureService"
    contract="testRef.IDataCaptureService" name="WebHttpBinding_IDataCaptureService" />

Here is an extract from the service web.config

        <service behaviorConfiguration="DataCaptureService.Service1Behavior" name="eCRB.Service.DataCapture">
            <endpoint address="" behaviorConfiguration="webBehaviour" binding="webHttpBinding" bindingConfiguration="" contract="eCRB.Service.IDataCaptureService">
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <behavior name="webBehaviour">
            <behavior name="DataCaptureService.Service1Behavior">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="false"/>
            <binding name="webBinding">
                <security mode="None">
                    <transport clientCredentialType="None"/>
</system.serviceModel> wcf rest service-reference
asked Jul 13 '11 at 11:07 TeamWild 1,240 4 31 51      You appear to have access to the service config, why not add ws endpoint and expose the metadata for consumption? –  Sinaesthetic Sep 24 '12 at 15:40


3 Answers


Take a look at ADO.Net data services, which specifically supports rest API's, and will return data in formats other than XML e.g. JSON


推荐:WCF与AJAX编程开发实践(2):支持ASP.NET AJAX的Web Service

Posted on 2010-06-20 17:34 Frank Xu Lei 阅读(520) 评论(8)   编辑 收藏 所属分类: SOA and EAI, WCF与AJAX编程开发实践  WCF与AJAX编程开发实践(1):AJAX基础

I see this is now re-branded WCF data services

answered Jul 13 '11 at 11:20 Matthew Evans 2,666 5 23 46


For the most part you can't. The reason is that a REST service doesn't expose any standardised metadata that VS2010 can use to add a service reference. I did say for the most part and that is because WCF Data Services, or OData to be more exact, does expose metadata and will allow you to do an add service reference.

answered Jul 13 '11 at 11:15 Maurice 25k 5 38 56


It is not possible to consume REST service with service reference from any project because service reference is only for SOAP services. How to consume REST service.

HttpClient is not part of any current WCF version. It was included in REST Starter Kit which was only community preview and never reached production final version and now it is included in Web-API which is CTP of REST components from future WCF version.

answered Jul 13 '11 at 11:13 Ladislav Mrnka 296k 48 552 601


推荐:Using The Amazon Web Service From ASP.NET

  In this article we will be utilizing the Amazon Web Service (AWS) from an ASP.NET web form. Instead of taking a comprehensive look at the entire API








您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱