2017-12-04 15 views
0

wcf Rest Service를 Angular JS 응용 프로그램으로 사용하고 있습니다. 나는 작업을 수행하는 몇 가지 방법을 만들었다. 먼저 클래스 라이브러리 프로젝트가있는 wcf 서비스가 있고 로컬 IIS에서이 프로젝트를 호스팅하는 다른 wcf 서비스 프로젝트를 만들었습니다. 로컬 호스트에서 wcf 서비스를 실행할 때 제대로 작동하지만 끝점을 찾을 수 없다는 예외를 throw하는 메서드 이름을 입력 할 때 url에 문제가 있습니다. 예 : http://localhost:52098/HalifaxIISService.svc/GetCustomers// 엔드 포인트를 찾을 수 없습니다. 여기Wcf 서비스가 로컬 호스트의 끝점을 찾지 못했습니다.

[OperationContract] 

     [WebInvoke(Method = "POST", 
     RequestFormat = WebMessageFormat.Json, 
     ResponseFormat = WebMessageFormat.Json, 
     UriTemplate = "/GetCustomers")] 
     string GetCustomers(string prefix); 

     [OperationContract] 
     [WebInvoke(Method = "POST", 
     RequestFormat = WebMessageFormat.Json, 
     ResponseFormat = WebMessageFormat.Json, 
     UriTemplate = "/GetAccountDetails")] 
     bool GetAccountDetails(string Account_Number); 

여기

내 인터페이스가가 .. 클래스 라이브러리 프로젝트에서 파일을 app.cong된다.

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <connectionStrings> 
    <add name="DBCS" connectionString="Data Source=;Initial Catalog=HalifaxDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> 
    <add name="HalifaxDatabaseEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=;initial catalog=HalifaxDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="HalifaxWCFProject.HalifaxService"> 
     <endpoint address="" binding="webHttpBinding" contract="HalifaxWCFProject.IHalifaxService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8733/Design_Time_Addresses/HalifaxWCFProject/HalifaxService/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 

    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 

다음은 IIS 용 service.svc 코드입니다. 여기

<%@ ServiceHost Language="C#" Debug="true" Service="HalifaxWCFProject.HalifaxService"%> 

여기
<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <connectionStrings> 
    <add name="DBCS" connectionString="Data Source=;Initial Catalog=HalifaxDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> 
    <add name="HalifaxDatabaseEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=;initial catalog=HalifaxDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <system.serviceModel> 
    <services> 
     <service name="HalifaxWCFProject.HalifaxService" behaviorConfiguration="mexBehaviour"> 
     <endpoint address="" binding="webHttpBinding" bindingConfiguration="" behaviorConfiguration="REST" contract="HalifaxWCFProject.IHalifaxService" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8080/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="mexBehaviour"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="REST"> 
      <webHttp /> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 

는 스크린 샷입니다 .. SVC는 파일에 대한 Web.config이다. click here to see the result web.config 파일에서 끝점을 정의했습니다. 나는이 오류가 끝점을 찾을 수 없다는 것이 궁금합니다.

답변

1

HTTP 포스트 끝점을 정의했기 때문에 "끝 점이 없음"오류가 발생합니다. 따라서 웹 브라우저에서 HTTP 요청을 보내면 테스트 할 수 없습니다.

코드를 작성하지 않고 서비스를 테스트하려면 Fiddler's 작성자 기능을 사용하여 HTTP 게시 요청을 보냅니다.

Fiddler Screenshot

또는 WebInvoke의 변경은 HTTP 요청을 얻을 수 있도록 때문이다.

[WebInvoke(Method = "GET", 
    RequestFormat = WebMessageFormat.Json, 
    ResponseFormat = WebMessageFormat.Json, 
    UriTemplate = "/GetCustomers")] 
+0

내가 테스트하는 웹 브라우저를 사용하도록 설정하는 방법을 설명 할뿐만 아니라 내 대답을 개정 한 – Mohammad

+0

GET 요청에 액세스하기 위해 변경 사항이 무엇이고 서비스 방법. –

1
당신은 포스트 방법을 시도 할 수