我正在开发一个 RESTful WCF 服务,然后我想从一个单独的 ASP.net 项目中使用它。
是否可以使用 ASP 项目中的服务引用来使用 REST 使用服务,或者是否所有服务引用都被视为 SOAP?
有很多使用服务库作为服务参考或使用 WCF 入门工具包使用 HttpClient 来使用 REST 服务的示例,但我还没有找到一个可以做我希望做的事情。
以下是添加服务引用时自动生成的 ASP.Net web.config 文件的摘录。如您所见,它提到了 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>
这是服务 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>