2009-08-04 10 views
1

私は数日間この問題を抱えています... 私はWCFクラスライブラリ - WebAPILibraryを設計しました。私のウェブプロジェクトも含まれている私の ソリューションの下にあります。AJAX対応のWCFサービスに関するヘルプが必要です(Web.Configの@ System.ServiceModelをご覧ください)

私は今、検索クエリにAJAX/JSON応答を有効にしようとしています。クライアントコードの例では

は、私は効果に何かを参照してください。

function btnsrch_onclick() { 

       var query = document.getElementById('q'); 
       var type = document.getElementById('type'); 

       $(document).ready(function(){ 
        $.getJSON("http://api.domain.com/services/trade.svc?q=" + query.value + "&type=" + type.value + "&format=json", 
         function(data){ 
          $.each(data.items, function(i,item){ 
          $("<img/>").attr("src", item.media.m).appendTo("#images"); 
           if (i == 3) return false; 
         }); 
        }); 
       }); 

       } 

私の問題は、ここまでになるまで、私は喜んで私のWebプロジェクトで私のWCFのクラスライブラリを参照してきたです。しかし、今私はSVCファイルを作成し、 私のjavascriptのAJAX/JSON呼び出しを実行するために使用する必要があるようです。

、私の質問は:

1)どのように私は私のWCFのクラスライブラリと協力してSVCファイルを作成するのですか? 2)Webプロジェクトの web.config用のsystem.ServiceModelの下に何を置く必要があるのか​​よくわかりません。何か魂が親切に私が現在持っているものを見て、私が助けてくれるものを で教えてもらえますか?

WebプロジェクトのSYSTEM.SERVICEMODEL(WEB.CONFIG):

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_ITradeService" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" 
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
      enabled="false" /> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" establishSecurityContext="true" /> 
      </security> 
     </binding> 
     <binding name="WSHttpBinding_IAuthService" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" 
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
      enabled="false" /> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" establishSecurityContext="true" /> 
      </security> 
     </binding> 
     <binding name="WSHttpBinding_IAuthService1" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" 
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
      enabled="false" /> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" establishSecurityContext="true" /> 
      </security> 
     </binding> 
     <binding name="WSHttpBinding_ITradeService1" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" 
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
      enabled="false" /> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" establishSecurityContext="true" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:8731/Design_Time_Addresses/Trade/" 
     binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITradeService" 
     contract="ITradeService" name="WSHttpBinding_ITradeService"> 
     <identity> 
      <dns value="localhost:8731" /> 
     </identity> 
     </endpoint> 
     <endpoint address="http://localhost:8731/Design_Time_Addresses/Authentication/" 
     binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAuthService" 
     contract="IAuthService" name="WSHttpBinding_IAuthService"> 
     <identity> 
      <dns value="localhost:8731" /> 
     </identity> 
     </endpoint> 
     <endpoint address="http://localhost:8731/Design_Time_Addresses/Authentication/" 
     binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAuthService1" 
     contract="Trezoro.WebAPI.Authentication.IAuthService" name="WSHttpBinding_IAuthService1"> 
     <identity> 
      <dns value="localhost:8731" /> 
     </identity> 
     </endpoint> 
     <endpoint address="http://localhost:8731/Design_Time_Addresses/Trade/" 
     binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITradeService1" 
     contract="Trezoro.WebAPI.Trade.ITradeService" name="WSHttpBinding_ITradeService1"> 
     <identity> 
      <dns value="localhost:8731" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 

WCFクラスライブラリSYSTEM.SERVICEMODEL(app.configを):

<system.serviceModel> 
     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
     <services> 
      <service behaviorConfiguration="WebAPILibrary.WebAPIBehavior" 
      name="Company.WebAPI.Trade.TradeService"> 
      <endpoint address="" binding="wsHttpBinding" contract="Company.WebAPI.Trade.ITradeService"> 
       <identity> 
       <dns value="localhost:8731" /> 
       </identity> 
      </endpoint> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
      <host> 
       <baseAddresses> 
       <add baseAddress="http://localhost:8731/Design_Time_Addresses/Trade/" /> 
       </baseAddresses> 
      </host> 
      </service> 
      <service behaviorConfiguration="WebAPILibrary.WebAPIBehavior" 
      name="Company.WebAPI.Authentication.AuthService"> 
      <endpoint address="" binding="wsHttpBinding" contract="Company.WebAPI.Authentication.IAuthService"> 
       <identity> 
       <dns value="localhost:8731" /> 
       </identity> 
      </endpoint> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
      <host> 
       <baseAddresses> 
       <add baseAddress="http://localhost:8731/Design_Time_Addresses/Authentication/" /> 
       </baseAddresses> 
      </host> 
      </service> 
     </services> 
     <behaviors> 
      <endpointBehaviors> 
      <behavior name="WebAPILibrary.WebAPIBehavior"> 
       <enableWebScript/> 
      </behavior> 
      </endpointBehaviors> 
      <serviceBehaviors> 
      <behavior name="WebAPILibrary.WebAPIBehavior"> 
       <!-- 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="True" /> 
      </behavior> 
      </serviceBehaviors> 
     </behaviors> 
     </system.serviceModel> 

答えて

1

あなたを参照することはありません他のプロジェクトではWCFライブラリ。これは、クラスライブラリとしてではなく、サービスとして使用するためのものです。

+0

お返事ありがとうございます。たぶん私は自分自身を不十分に説明したでしょうか?私はその部分を間違ってやったとは思わない。 WCFライブラリを設計した後、Webプロジェクトで「サービスリファレンス」を使用してエンドポイントを呼び出しました。したがって、私はAuthServiceとTradeServiceの2つのエンドポイントを取り入れました。私はAuthServiceClientとTradeServiceClientをインスタンス化することで、プロジェクト内の各サービスのメソッドを使用しています。 これは間違っていますか?もしそうなら、私はそれが正しいことをなぜ必要としているのかを親切に説明できますか? ありがとうございます。 –

+0

あなたは「今までのWebプロジェクトでWCFクラスライブラリを喜んで参照していましたが、今はSVCファイルを作成する必要があると私の問題です。どのように.svcファイルなしでサービス参照を作成しましたか? URLテキストボックスに何を入力しましたか? –

+0

OK、ありがとう。 Webプロジェクトで「サービス参照の追加」を実行すると、ウィンドウに「発見」ボタンが表示されます。私がそれをクリックすると、私の2つのサービスのMEXエンドポイントを指しています。たとえば、「認証」の場合、「アドレス」ボックスに次のように表示されます。 http:// localhost:8731/Design_Time_Addresses/Authentication/mex これはWebサービス(Webサービス)にサービスを追加してからサービスメソッドにアクセスできます。 私は間違って何をしていますか? SVCファイルをWebプロジェクトに追加し、サービスライブラリで作成したすべてのメソッドのプロキシとして機能するコードを記述する必要がありますか?おかげさまで –

関連する問題