2014-07-10 3 views
0

IIS에서 WCF 서비스를 실행하고 있습니다. 클라이언트는 net.tcp를 통해 연결합니다. 하나의 실제 머신이 클라이언트 어플리케이션의 두 인스턴스를 열 때까지 모든 것이 잘 작동합니다. 그런 다음 두 번째 애플리케이션 만 서비스에서 제공됩니다.하나의 실제 컴퓨터에서 다른 WCF 서비스에 대한 여러 인스턴스

하나의 컴퓨터가 srvAddress : port/service.svc에 대한 연결을 여는 포트 문제이며 서버가 응답해야하는 클라이언트 인스턴스를 알지 못한다고 가정합니다.

첫 번째 질문 : client1 (pc1)에서 ip : port/service.svc를 열면 WCF가 응답에 사용할 로컬 클라이언트 포트는 무엇입니까? 그런 다음 client2 (아직 pc1)에서 ip : port/service.svc를 열면 WCF가 제대로 처리하지 못하는 이유는 무엇입니까?

서버 :

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, InstanceContextMode = InstanceContextMode.PerSession)] 
public class WCFService : IWCFService 
{ 
    public State OpenSession(string clientKey) 
    { 
     Callback = OperationContext.Current.GetCallbackChannel<IWCFServiceCallback>();    
    } 
} 

클라이언트 :

var callback = new WCFServiceCallback(); 
var instanceContext = new InstanceContext(callback); 
Server = new WCFServiceClient(instanceContext); 
Server.OpenSession("secret"); 

WCF 구성 서버

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <customErrors mode="Off"/> 
    <compilation/> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <!-- Add the following element to your service behavior configuration. --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <!--Hosting in a IIS: --> 
     <service name="WCFServiceLibrary.Service.WCFService"> 
     <endpoint address="net.tcp://myservice.com:808/Service.svc" binding="netTcpBinding" bindingConfiguration="InsecureTcp" contract="WCFServiceLibrary.Contract.IWCFService" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://myservice.com/Service/"/> 
      </baseAddresses> 
     </host> 
     <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/> 
     </service> 
    </services> 
    <bindings> 
     <netTcpBinding> 
     <binding name="InsecureTcp" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> 
      <security mode="None" /> 
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
</configuration> 

WCF 구성 클라이언트

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
     <section name="Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/> 
    </sectionGroup> 
    </configSections> 

    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="NetTcpBinding_IWCFService"> 
      <security mode="None"/> 
     </binding> 
     </netTcpBinding> 
    </bindings> 

    <client> 
     <endpoint address="net.tcp://myservice.com/Service.svc" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IWCFService" contract="ServiceReference.IWCFService" name="NetTcpBinding_IWCFService"/> 
    </client> 
    </system.serviceModel> 

    <userSettings /> 

    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/> 
    </startup> 

</configuration> 
+0

WCF 클라이언트 구성에 이상하게 보입니다. 그것은 단지 하나의 서비스 만 제공한다는 것이 놀랍지는 않습니다. 전체 구성 파일을 볼 수 있습니까? – Aelphaeis

+0

안녕하세요 @Aelphaeis 요청하신대로 구성을 업데이트했습니다 :-) – libjup

답변

0

난 정말 모르겠어요 무슨 잘못; 그러나이 단계가 디버깅하는 데 도움이 될 것으로 판단됩니다.

WCF에는 클래스 라이브러리의 출력 형식이 있어야합니다. 동일한 솔루션에서 다른 프로젝트를 만들고 새 프로젝트에 대한 참조로 WCF 서비스를 추가하십시오.

다음으로 콘솔에서 WCF 서비스를 수동으로 엽니 다. 다음과 비슷한 코드를 사용하면됩니다.

 //Alternatively you can use : 
     //ServiceHost host = new ServiceHost(typeof(ApiTestService), new Uri(PipeService)); 
     Api api = new ApiTestService(); 
     ServiceHost host = new ServiceHost(api,new Uri(PipeService)); 

     //Add all your bindings. 
     host.AddServiceEndpoint(typeof(IApiService), new NetNamedPipeBinding(), ApiPipeServiceName); 

     host.BeginOpen(OnOpen, host); 
     Console.ReadLine(); 
     host.BeginClose(OnClose, host); 

여기서 OnOpen과 OnClose는 아래처럼 보입니다.

void OnOpen(IAsyncResult ar) 
    { 
     ServiceHost service = (ServiceHost)ar.AsyncState; 
     service.EndOpen(ar); 
    } 
    void OnClose(IAsyncResult ar) 
    { 
     ServiceHost service = (ServiceHost)ar.AsyncState; 
     service.EndClose(ar); 
    } 

그런 다음 서비스 참조를 다시 가져 와서 구성 파일을 비교하십시오. 두 요청 모두 서비스 중이라는 것을 알게되면 WCF 구성에 문제가있는 것입니다. 여전히 두 번째 요청을 처리 할 수 ​​없다는 것을 알게되면 서비스에 수동으로 액세스해야합니다. 즉, 서비스에 대한 프록시를 만들어서 사용할 수 있습니다.

public class MyPipeClient : IMyService, IDisposable 
{ 
    //Sub IMyService with your service interface contract 
    ChannelFactory<IMyService> myServiceFactory; 

    public MyPipeClient() 
    { 
     // Sub NetNamedPipeBinding with your bindings. 
     myServiceFactory = new ChannelFactory<IMyService>(new NetNamedPipeBinding(), new EndpointAddress(Constants.myPipeService + @"/" + Constants.myPipeServiceName)); 


    } 

    //Implementation Details no one cares about would go here 
    //... 
    //Example where Hello is one of the functions from my Service. 
    public String Hello(String Name) 
    { 
     return Channel.Hello(Name); 
    } 


    public IMyService Channel 
    { 
     get 
     { 
      return myServiceFactory.CreateChannel(); 
     } 
    } 
} 

이 문제가 무엇 이건 당신은 매우 가까운 가리켜 야 :

는 프록시 클래스의 예가 될 것입니다.

관련 문제