ITKeyword,专注技术干货聚合推荐

注册 | 登录

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

itPublisher 分享于

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

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

前一篇《jQuery.Ajax()执行WCF Service的方法》http://www.cnblogs.com/insus/p/3727875.html 我们有练习在asp.net mvc应用程序中,POST 数据去wcf service并执

I am developing a RESTful WCF service which I then want to consume from a separate ASP.net 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.

  <system.serviceModel>
  <bindings>
   <customBinding>
    <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" />
     </textMessageEncoding>
    </binding>
   </customBinding>
  </bindings>
  <client>
   <endpoint binding="customBinding" bindingConfiguration="WebHttpBinding_IDataCaptureService"
    contract="testRef.IDataCaptureService" name="WebHttpBinding_IDataCaptureService" />
  </client>
 </system.serviceModel>

Here is an extract from the service web.config

<system.serviceModel>
    <services>
        <service behaviorConfiguration="DataCaptureService.Service1Behavior" name="eCRB.Service.DataCapture">
            <endpoint address="" behaviorConfiguration="webBehaviour" binding="webHttpBinding" bindingConfiguration="" contract="eCRB.Service.IDataCaptureService">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <endpointBehaviors>
            <behavior name="webBehaviour">
                <webHttp/>
            </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <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"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <webHttpBinding>
            <binding name="webBinding">
                <security mode="None">
                    <transport clientCredentialType="None"/>
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
</system.serviceModel>
asp.net 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
3

解决方法

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

http://msdn.microsoft.com/en-us/data/bb931106

UPDATE:

推荐: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


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

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

如果您没有收到激活邮件,请注意检查垃圾箱。