2012-12-06 6 views
7

다른 URL에서 다른 기능을 참조하는 2 개의 끝점을 제공하도록 구성하려고하는 WCF 서비스가 있습니다.WCF 서비스에서 2 가지 다른 서비스 계약에 2 개의 끝점을 표시합니다.

은 내가 갖고 싶어하는 방법 A는, B, C, 및 서비스 2, 노출 방법의 D, E. 내가 로컬 호스트/WebServiceName/서비스 1을 모두 검색 할 수 있도록하려면 노출, 서비스 1입니다/서비스 .svclocalhost/WebServiceName/Service2/Service.svc. 참조

다른 응용 프로그램 로컬 호스트/WebServiceName/서비스 1/Service.svc는 방법 A를 포함하는 경우에만 인터페이스를 볼 수, B와 C 그들은 서비스 2 인터페이스에 대한 아무것도 못한다. 그리고 서비스 2에 대해서도 마찬가지입니다. 내 WCF 서비스의

지금까지 정의한 두 개의 인터페이스,I_Service1 및 I_Service2.

나는 그렇게처럼 내 Web.config의 두 끝점을 추가 한 :

<endpoint address="http://localhost/WebServiceName/Service1/" binding="wsHttpBinding" contract="WebServiceName.I_Service1" bindingConfiguration="Binding1" /> 
<endpoint address="http://localhost/WebServiceName/Service2/" binding="wsHttpBinding" contract="WebServiceName.I_Service2" bindingConfiguration="Binding2" /> 
enpoint에서 전체 주소를 사용하는 제안은 여기에서 유래

: 여전히 Multiple endpoints under IIS

하지만, 내가 찾아 볼 수 없습니다 localhost/WebServiceName/Service1/Service.svc.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. 

내가 성공적으로 로컬 호스트/WebServiceName/Service.svc를 찾아 볼 수 있고, WSDL은, B, C, D, E.을 방법 A를 포함하지만 이것은 내가 원하는 행동의 잘못한다 : 내가받을 수 있습니다.

내가 놓친 것이 있습니까?

업데이트 :이 기사에 이어 http://allen-conway-dotnet.blogspot.ro/2011/09/exposing-multiple-binding-types-for.html 나는 이러한 종점에 대해 두 가지 계약 서비스를 만들었습니다. 그러나 현재 내가 찾아 볼 때 서비스 1 만 있습니다. 서비스 2이 분명히 존재하지 않습니다 (HTTP 404 오류 관련 문제가 나타남).

<services> 
    <service behaviorConfiguration="WebServiceName.ServiceBehavior1" name="WebServiceName.Service1"> 
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" 
    contract="WebServiceName.I_Service1" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/WebServiceName/Service1/Service.svc" /> 
     </baseAddresses> 
    </host> 
    </service> 
    <service behaviorConfiguration="WebServiceName.ServiceBehavior2" name="WebServiceName.Service2"> 
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" 
    contract="WebServiceName.I_Service2" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/WebServiceName/Service2/Service.svc" /> 
     </baseAddresses> 
    </host> 
    </service> 
    </services> 

답변

1

이 문제에 대한 나의 해결책은 두 개의 인터페이스를 구분하기 위해 내 웹 서비스에 두 개의 .svc 파일을 통합하는 것이 었습니다. 그런데 localhost/WebServiceName/Service1.svclocalhost/WebServiceName/Service2.svc입니다. 엔드 포인트 구성으로

<services> 
    <service behaviorConfiguration="WebServiceName.ServiceBehavior1" name="WebServiceName.Service1"> 
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" 
    contract="WebServiceName.I_Service1" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/WebServiceName/Service1.svc" /> 
     </baseAddresses> 
    </host> 
    </service> 
    <service behaviorConfiguration="WebServiceName.ServiceBehavior2" name="WebServiceName.Service2"> 
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding2" 
    contract="WebServiceName.I_Service2" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/WebServiceName/Service1.svc" /> 
     </baseAddresses> 
    </host> 
    </service> 
    </services> 

이 솔루션을 필요하지 최고의 하나 (클라이언트가 정말 원하는 경우,이 서비스는 2 개의 다른 인터페이스를 노출 찾을 수 있지만 다른 자격 증명을 보호 할 수 있습니다/토큰). 그러나 그 순간 나는 그걸로 갈 것이다.

1

난 당신이 설명하는 일을 만들려고 :

구성은 같다. 이 모든 것이 성공합니다. 제발 당신을 위해 분명한 단계가 있다면 화 내지 마세요. 따라서 :

  1. WCF 서비스 응용 프로그램 프로젝트 만들기.
  2. 두 개의 WCF 서비스 항목을 추가합니다 (기본적으로 인터페이스 및 SVC 파일 생성).
  3. 웹 응용 프로그램 프로젝트를 만듭니다.
  4. 'Discover'버튼을 사용하여 두 개의 서비스 참조 (Web App Project를 마우스 오른쪽 버튼으로 클릭 ==> 서비스 참조 추가)를 추가하십시오 (두 개의 웹 서비스가 표시되어야 함).
  5. 그게 전부입니다.기본적으로

나는 웹 응용 프로그램 프로젝트에서 다음의 Web.config를 가지고 :

 <system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
     maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    <binding name="BasicHttpBinding_IService2" closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
     maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://localhost:3597/Service1.svc" binding="basicHttpBinding" 
    bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" 
    name="BasicHttpBinding_IService1" /> 
    <endpoint address="http://localhost:3597/Service2.svc" binding="basicHttpBinding" 
    bindingConfiguration="BasicHttpBinding_IService2" contract="ServiceReference2.IService2" 
    name="BasicHttpBinding_IService2" /> 
</client> 

당신은 WCF 프로젝트 및 업데이트 WebReferences을 다시 시도 할 수 있습니다. 다음과 같이

+2

확실한 단계를 설명하는 데는 아무런 문제가 없습니다. 대부분의 시간은 우리가 잊어 버린 사람들입니다. 그럼에도 불구하고, 내 질문은 두 개의 다른 웹 서비스가 아니라 두 개의 끝점을 사용하여 단일 웹 서비스를 구성하는 방법에 관한 것입니다. 또한 구성 부분은 Web.config 또는 Web.config를 참조하는 응용 프로그램의 app.config가 아닌 해당 Web Service web.config에서 구성해야하는 항목에 대한 것입니다. –

3

난 항상 이런 짓을 한 방법은 다음과 같습니다 서비스에 대한 하나의 "기본 주소"로 설정하고 엔드 포인트가 기본 주소에 추가하는 등 다양한 텍스트를 해결 지정 ...

<service name="MyNamespace.MyService"> 
    <endpoint address="FirstEndpointAddress" binding="netTcpBinding" 
     name="FirstEndpointName" 
     contract="MyNamespace.FirstEndpointContract" /> 
    <endpoint address="SecondEndpointAddress" binding="netTcpBinding" 
     name="SecondEndpointName" 
     contract="MyNamespace.SecondEndpointContract" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="net.tcp://localhost:8733/MyBaseAddress" /> 
     </baseAddresses> 
    </host> 
    </service> 

따라서 기본 주소는 localhost/WebServiceName이고 엔드 포인트 1의 엔드 포인트 주소는 Service1/Service.svc 일 수 있습니다. 마찬가지로 엔드 포인트 2의 경우 Service2/Service.svc 일 수 있습니다. 끝점 주소에 전체 주소를 넣으라는 조언을 따랐다는 것을 알 수 있습니다.하지만 내가 말할 수있는 것은 성공으로이 방법을 사용했다는 것입니다.

+0

이 방법을 사용해도 localhost : 8733/MyBaseAddress/FirstEndpointName/Service.svc에 대한 HTTP 404 오류가 발생합니다 (클라이언트에서 서비스 참조를 로컬 호스트로 추가하려고 시도 할 때도 발생합니다 : 8733/MyBaseAddress/Service.svc가 두 가지 인터페이스가 모두 내 경우에 나쁘다). web.config가 아니라 IIS 측면에서 구성 오류가있을 수 있습니까? 두 개의 끝점에 대해 두 개의 가상 디렉터리 생성을 시도했지만 두 가상 디렉터리가 첫 번째 끝점 인터페이스에 바인딩됩니다. –

+1

끝점 중 하나에 "FirstEndpointName/Service.svc"주소를 지정하지 않았다면 이전에 사용하던 주소를 기대하지 않을 것입니다. 엔드 포인트 이름과 엔드 포인트 주소가 다른 점을 기억하십시오. – Martin

+0

궁극적 주소가된다 : 로컬 호스트 : 8733/MyBaseAddress/Service.svc/FirstEndpointAddress 및 로컬 호스트 : 8733/MyBaseAddress/Service.svc 클라이언트 코드에서/SecondEndpointAddress : var에 svcClient = 새로운 ServiceReference1.ServiceClient ("SecondEndpointName"); – hB0