지금 며칠 동안이 문제가 발생했습니다 ... 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;
});
});
});
}
내 문제가 최대이 시점까지, 내가 행복하게 내 웹 프로젝트에서 내 WCF 클래스 라이브러리를 참조 된입니다. 하지만 지금은 SVC 파일을 만들어서 자바 스크립트 AJAX/JSON 호출을 실행해야합니다.
내 질문은 :
1) 내 WCF 클래스 라이브러리와 함께 협력하여 SVC 파일을 만들려면 어떻게해야합니까? 2) 웹 프로젝트의 서비스 모델 인 web.config를 system.ServiceModel에 넣어야하는지 잘 모르겠습니다. 어떤 종류의 영혼이 친절하게 내가 현재 가지고있는 것을보고, 내가 무엇을 해야하는지 에 대해 조언 해 줄 수 있습니까?
웹 프로젝트는 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>
응답 해 주셔서 감사합니다. 어쩌면 나 자신을 제대로 설명하지 않았을까요? 나는 그 부분을 잘못했다고 생각하지 않는다. WCF 라이브러리를 디자인 한 다음 웹 프로젝트에서 "서비스 참조"선택을 사용하여 끝점을 호출했습니다. 따라서 AuthService와 TradeService라는 두 개의 끝점을 통합했습니다. AuthServiceClient 및 TradeServiceClient를 인스턴스화하여 프로젝트의 각 서비스 메소드를 사용하고 있습니다. 잘못 되었습니까? 그렇다면 친절하게 이유와 내가해야 할 일이 정확하다는 것을 설명해 주시겠습니까? 미리 감사드립니다. –
당신은 "지금까지 웹 프로젝트에서 WCF 클래스 라이브러리를 행복하게 참조하고 있었지만 지금은 SVC 파일을 만들어야 할 것 같습니다."라고 대답했습니다. .svc 파일없이 서비스 참조를 어떻게 만들었습니까? URL 입력란에 무엇을 입력 했습니까? –
그래, 고마워. 웹 프로젝트에 "서비스 참조 추가"를 실행하면 창에 "검색"버튼이 표시됩니다. 클릭하면 내 두 서비스의 MEX 끝점을 가리 킵니다. 예를 들어 "인증"의 경우 "주소"상자에 다음을 입력합니다. http : // localhost : 8731/Design_Time_Addresses/Authentication/mex 그러면 웹 서비스 (웹 서비스)에 서비스가 추가되고 서비스 메소드에 액세스 할 수 있습니다. 내가 뭘 잘못하고 있니? SVC 파일을 웹 프로젝트에 추가하고 서비스 라이브러리에서 작성한 모든 메소드의 프록시 역할을하는 코드를 작성해야합니까? 감사합니다. . –