1

WCF 서비스에서 콜백을 만들려고합니다. 지금까지는 basicHttpBinding을 사용하고 있었으므로 netTcpBinding에 대한 다른 끝점을 추가하고 싶습니다. 서비스는 이미 IIS에서 호스팅됩니다. 첫째로 그것은 IIS 6에서 호스팅했지만, 나는 그래서, 나는 다음과 같은 오류 받고 있어요 IIS 7WCF netTcpBinding 문제 : 계약서에 Duplex가 필요하지만 Binding 'BasicHttpBinding'이 지원하지 않거나 올바르게 지원하도록 구성되지 않았습니다.

설치 :

: 로그를 볼 때

The requested service, 'net.tcp://localhost:1801/MyServiceName.svc/NetTcpExampleAddress' could not be activated. See the server's diagnostic trace logs for more information.

을,이 메시지입니다 enter image description here

그래서 주요 오류 : 여기

Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it.

내 눌러 확인하다 g 파일 :

서버에 대한 내 의 Web.config :
<system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="demoServiceNetTcpBinding"> 
      <security mode="None"/> 
     </binding> 
     </netTcpBinding> 
     <basicHttpBinding> 
     <binding name="demoServiceHttpBinding" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxReceivedMessageSize="2147483647"> 
      <security mode="None"/> 
     </binding>   
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service name="MyServerName.MyServiceName"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:1801/MyServiceName.svc/"/> 
      <add baseAddress="http://localhost:1800/MyServiceName.svc/"/> 
      </baseAddresses> 
     </host> 
    <endpoint 
     address="NetTcpExampleAddress" 
     binding="netTcpBinding" 
     bindingConfiguration="demoServiceNetTcpBinding" 
     contract="MyServerName.SharedContract.IMyServiceName"/> 
    <endpoint 
     address="BasicHttpExampleAddress" 
     binding="basicHttpBinding" 
     bindingConfiguration="demoServiceHttpBinding" 
     contract="MyServerName.SharedContract.IMyServiceName"/> 
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
      <serviceMetadata httpGetEnabled="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

의 App.config 클라이언트에 대한 : 내 IIS에서

<system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="demoServiceNetTcpBinding"> 
      <security mode="None"/> 
     </binding> 
     </netTcpBinding> 
     <basicHttpBinding> 
     <binding name="demoServiceHttpBinding" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxReceivedMessageSize="2147483647"> 
      <security mode="None"/> 
     </binding>   
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint name="NetTcpExampleName" 
      address="net.tcp://localhost:1801/DicomQueryService.svc/NetTcpExampleAddress" 
      bindingConfiguration ="demoServiceNetTcpBinding" 
      contract="MyServerName.SharedContract.IMyServiceName" 
      binding="netTcpBinding" /> 
     <endpoint name="BasicHttpExampleName" 
      address="http://localhost:1800/MyServiceName.svc/BasicHttpExampleAddress" 
      bindingConfiguration ="demoServiceHttpBinding" 
      contract="MyServerName.SharedContract.IMyServiceName" 
      binding="basicHttpBinding" /> 
    </client> 
    </system.serviceModel> 

설정 :

enter image description here

enter image description here

필요한 경우 다른 코드가 있으면 알려 주시면 질문을 업데이트하겠습니다.

편집 1 :

public class MyCommandClass : IMyServiceCallback 
{ 
    public MyCommandClass() 
    { 
     var ctx = new InstanceContext(new MyCommandClass()); 
     DuplexChannelFactory<MyServerName.SharedContract.IMyServiceName> channel = new DuplexChannelFactory<MyServerName.SharedContract.IMyServiceName>(ctx, "NetTcpExampleName"); 
     MyServerName.SharedContract.IMyServiceName clientProxy = channel.CreateChannel(); 
     clientProxy.MyFunction(); //debug point is comming here and then it throws the error 
     clientProxy.ProcessReport(); 
     (clientProxy as IClientChannel).Close(); 
     channel.Close(); 
    } 

    public void Progress(int percentageCompleted) 
    { 
     Console.WriteLine(percentageCompleted.ToString() + " % completed"); 
    } 
} 

인터페이스 (서버 : 여기

코드에서, 나는 (클라이언트 측에서) 클라이언트에서 서비스를 호출하고있어 방법의 자세한 내용입니다 측)으로 정의된다 :

[ServiceContract(CallbackContract = typeof(IMyServiceCallback))] 
public interface IMyServiceName 
{ 
    [OperationContract] 
    void MyFunction(); 

    [OperationContract(IsOneWay = true)] 
    void ProcessReport(); 
} 

public interface IMyServiceCallback 
{ 
    [OperationContract(IsOneWay = true)] 
    void Progress(int percentageCompleted);  
} 

및 서버 측에서 서비스()로서 정의된다 :

public class MyServiceName: IMyServiceName 
{ 
    public void MyFunction() 
    { 
     //do something 
    } 

    public void ProcessReport() 
    { 
     //trigger the callback method 
     for (int i = 1; i <= 100; i++) 
     { 
      Thread.Sleep(100); 
      OperationContext.Current.GetCallbackChannel<IMyServiceCallback>().Progress(i); 
     } 
    } 
} 

내 방법은 지금까지 데모입니다. 이 질문과 관련된 오류가 수정되면 메서드를 개발하는 것으로 시작하겠습니다.

+0

demoQueryServiceHttpBinding이 demoServiceHttpBinding으로되어 있습니까? – jcmcbeth

+0

클라이언트에서 서비스로 전화하는 방법을 게시 할 수 있습니까? – jcmcbeth

+0

@jcmcbeth demoQueryServiceHttpBinding의 이름을 demoServiceHttpBinding으로 변경했습니다. 질문을 쓰는 동안 이것은 구문 오류 일뿐입니다. 주요 쟁점은 여전히 ​​남아 있습니다. 또한 서비스를 호출하는 방법과 관련된 더 많은 코드 (편집 1에서)로 질문을 업데이트했습니다. – delux

답변

1

서비스 계약에 양방향 연결이 필요합니다 (사용자에게 ServiceCallback 속성이 있어야 함). 따라서이 서비스가 노출하는 모든 엔드 포인트는 이중 연결을 지원해야합니다. Net.tcp가 지원하지만 basicHttp는 지원하지 않으므로 basicHttp를 서비스와 함께 사용할 수 없습니다.

+0

Web.config에서 몇 가지 변경 사항을 수행했습니다. "BasicHttpExampleAddress"끝점을 제거하고 그 문제를 해결했습니다. 또한 "mexcp"로 ​​"mex"엔드 포인트의 이름을 변경했습니다. 이렇게하면 지금 내 문제가 해결되었지만 여기에 "basicHttpBining"을 갖고 싶다면 어떻게해야할까요? 콜백없이 "basicHttpBining"과 콜백을 통해 "netTcpBinding"이라는 다른 종점을 가질 수 있습니까? – delux

+1

두 가지 계약을 사용해야합니다. 계약은 클라이언트가 수행 할 수있는 작업을 정의하기 때문입니다. 계약서에 콜백이 있다고하면 클라이언트는 콜백을 서비스에 연결하는 방법에 관계없이 콜백을 사용할 수 있어야합니다. 서비스가 다른 기능을 수행하는 경우 (즉, 콜백이없는 경우) 'ServiceCallbackAttribute'를 사용하지 않고 다른 서비스 클래스를 구현하는 하나 이상의 계약을 정의하십시오. 그런 다음 basicHttp 끝점을 통해이를 노출 할 수 있습니다. 두 서비스는 여전히 동일한 '백엔드'를 내부적으로 운영에 사용할 수 있습니다. –