2010-07-22 4 views
0

WCF 서비스를 Windows 서비스로 호스팅하고 있습니다.WCF 여러 서비스 끝점

아래의 스냅 샷.

myHost = new ServiceHost(typeof(AnalyticsService)); 
Uri address = new Uri("http://localhost:8080/MathServiceLibrary"); 

WSHttpBinding binding = new WSHttpBinding(); 
binding.MaxReceivedMessageSize = 2147483647; 
binding.MaxBufferPoolSize = 2147483647; 

//binding.Security.Mode = SecurityMode.None; 
Type contract = typeof(IAnalyticsService); 

myHost.AddServiceEndpoint(contract,binding,address); 

이전에 서비스를 로컬에서만 노출하고있었습니다. 내 네트워크의 다른 컴퓨터에서도 서비스를 호출 할 수 있도록 다른 ServiceEndpoint를 추가하고 싶습니다.

은 내가 위의 코드에 다음과 같이 뭔가를 추가해야합니다 가정 : APP의 설정 보이는 지금

myHost = new ServiceHost(typeof(AnalyticsService)); 

Uri address = new Uri("http://localhost:8080/MathServiceLibrary"); 
Uri new address = new Uri("http://xxx.xxx.xxx:8080/MathServiceLibrary"); 

WSHttpBinding binding = new WSHttpBinding(); 
binding.MaxReceivedMessageSize = 2147483647; 
binding.MaxBufferPoolSize = 2147483647; 

Type contract = typeof(IAnalyticsService); 

myHost.AddServiceEndpoint(contract, binding, address); 
myHost.AddServiceEndpoint(contract, binding, newaddress); 

내 현재 서비스 라이브러리를 같은 :

<system.serviceModel> 
    <services> 
     <service behaviorConfiguration="ServiceLibrary.Service1Behavior" 
     name="ServiceLibrary.AnalyticsService"> 
     <endpoint address="" binding="wsHttpBinding" contract="ServiceLibrary.IAnalyticsService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8731/Design_Time_Addresses/ServiceLibrary/Service1/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceLibrary.Service1Behavior"> 
      <!-- 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="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

app.config 서비스 도서관에있는 동안 호스트가

<system.serviceModel> 
    <services> 
     <service name="ServiceLibrary.AnalyticsService" 
       behaviorConfiguration ="MathServiceMEXBehavior"> 
     <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange"/> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8080/MathService"/> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="MathServiceMEXBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

내가 추가해야한다고 가정합니다. 기본 주소를 외부 (비 로컬 호스트) 주소가있는 서비스 라이브러리 파일에 추가하십시오. 서비스 라이브러리 파일에서 무엇을 변경해야하는지 혼란 스럽습니다.

+0

코드 또는 XML을 게시하는 경우 텍스트 편집기에서 해당 줄을 강조 표시하십시오. 편집기 툴바에서 "코드"버튼 (101 010)을 클릭하면 멋지게 포맷하고 구문을 강조 할 수 있습니다! –

답변

0

아니요. 두 번째 http 기반 기본 주소를 추가 할 수 없습니다. 프로토콜 당 하나만 선택하면됩니다. 하나는 http, 하나는 net.tcp 등입니다.

서비스 호스트 응용 프로그램의 경우 app.config에 두 번째 끝점을 만들면됩니다 (서비스 라이브러리의 app.config는 사용되지 않으며 해당 파일은 잊어 버리고 완전한 주소를 할당하십시오) .

<system.serviceModel> 
    <services> 
     <service name="ServiceLibrary.AnalyticsService" 
       behaviorConfiguration ="MathServiceMEXBehavior"> 

     <endpoint name="firstEndpoint" 
        address="" 
        binding="wsHttpBinding" 
        contract="IAnalyticsService" /> 

     <endpoint name="secondEndpoint" 
        address="http://xxx.xxx.xxx:8080/MathServiceLibrary" 
        binding="wsHttpBinding" 
        contract="IAnalyticsService" /> 

     <endpoint address="mex" 
        binding="mexHttpBinding" 
        contract="IMetadataExchange"/> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8080/MathService"/> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 

는 그래서 firstEndpoint은 기본 주소를 사용하는 것이 당신은 secondEndpoint 특정, 정규화 된 URL을 사용하는 반면

http://localhost:8080/MathService 

아래를 호출 할 수있을 거라고 당신이 호출 할 수있을 것 그것 아래에

http://xxx.xxx.xxx:8080/MathServiceLibrary 

그러나 : 왜 두 번째 종점을 가지고 싶니 ?? 다른 프로토콜을 노출하려면 일반적으로 두 번째 끝 점이 있어야합니다 (예 : 일반적으로 하나의 http, 하나의 https, 하나의 net.tcp 끝점 등이 있습니다. 동일한 계약과 동일한 바인딩을 가진 두 개의 별도 HTTP 끝 점이 실제로 내게 많은 의미를 갖지는 않습니다 .....

+0

나는 더 분명해야했다. 필자가 정말로하고 싶은 것은 localhost를 IP로 바꾸고 로컬 컴퓨터의 클라이언트에서 서비스를 호출 할 수있을뿐만 아니라 다른 컴퓨터에서도 서비스를 사용할 수있게하는 것입니다. – bearrito