1

这几天我一直遇到一些问题......我设计了一个 WCF 类库 - WebAPILibrary。它在我的解决方案下,其中还包含我的网络项目。

我现在正在尝试启用对搜索查询的 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) 我不太确定我需要在 system.ServiceModel 下为我的 web 项目的 web.config 放置什么。有没有好心人看看我目前拥有的东西,并就我需要做什么提供建议?

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>
4

1 回答 1

1

您永远不应在任何其他项目中引用您的 WCF 库。它旨在用作服务,而不是用作类库。

于 2009-08-04T18:58:14.670 回答