0

別の ASP.net プロジェクトから使用したい RESTful WCF サービスを開発しています。

REST を使用してサービスを利用するために ASP プロジェクト内からサービス参照を使用することは可能ですか、それともすべてのサービス参照は SOAP として扱われますか?

サービス ライブラリをサービス参照として使用したり、HttpClient を使用して WCF スターター ツールキットを使用して 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>
4

3 に答える 3

3

残りの API を具体的にサポートし、JSON などの XML 以外の形式でデータを返す ADO.Net データ サービスを見てみましょう。

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

アップデート:

これは現在、WCF データ サービスのブランド名が変更されているようです

于 2011-07-13T11:20:21.533 に答える
2

ほとんどの場合、できません。その理由は、REST サービスは、VS2010 がサービス参照を追加するために使用できる標準化されたメタデータを公開していないためです。大部分は言いましたが、それは WCF Data Services (より正確には OData) がメタデータを公開し、サービス参照を追加できるようにするためです。

于 2011-07-13T11:15:56.407 に答える
1

サービス参照はSOAPサービス専用であるため、どのプロジェクトからのサービス参照でもRESTサービスを利用することはできません。REST サービスの使用方法

HttpClient現在の WCF バージョンの一部ではありません。REST Starter Kit に含まれていたのはコミュニティ プレビューのみであり、製品の最終バージョンに到達することはありませんでしたが、将来の WCF バージョンから REST コンポーネントの CTP であるWeb-APIに含まれるようになりました。

于 2011-07-13T11:13:34.790 に答える