2012-06-13 3 views
0

wsDualHttpBinding을 사용하여 간단한 콜백 서비스를 만들고 ASP.net 웹 응용 프로그램을 사용하여 호출하려고했지만 콜백 이벤트가 발생하지 않습니다. 콘솔 클라이언트로 시도해 보았지만 제대로 작동합니다. 내가하는 실수를 도와주세요. 나는 서비스를 실행하는 ASP.netWCF wsDualHttpBinding ASP.NET 클라이언트 콜백이 작동하지 않습니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.Threading; 

[ServiceContract(CallbackContract=typeof(IClientCallback))] 
public interface ITemperature 
{ 
    [OperationContract(IsOneWay=true)] 
    void RegisterForTempDrops(); 
} 

public interface IClientCallback 
{ 
    [OperationContract] 
    bool TempUpdate(double temp); 
} 

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Reentrant)] 
public class Temperature : ITemperature 
{ 
    public void RegisterForTempDrops() 
    { 
     OperationContext ctxt = OperationContext.Current; 
     IClientCallback callBack = ctxt.GetCallbackChannel<IClientCallback>(); 
     Thread.Sleep(3000); //simulate update happens somewhere; for example monitoring a database field 
     callBack.TempUpdate(10); 
    } 

} 

의 app.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="Temperature" behaviorConfiguration="ServiceBehavior"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:5050/duplexservice" /> 
      </baseAddresses> 
     </host> 
     <!-- Service Endpoints --> 
     <endpoint address="http://localhost:5050/duplexservice" binding="wsDualHttpBinding" contract="ITemperature" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehavior">  
      <serviceMetadata httpGetEnabled="true"/>  
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

Windows Form에 새로운 오전.

using System.Text; 
using System.Windows.Forms; 
using System.ServiceModel; 

namespace DuplexService 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     internal static ServiceHost myServiceHost = null; 
     private void button1_Click(object sender, EventArgs e) 
     { 
      myServiceHost = new ServiceHost(typeof(Temperature)); 
      myServiceHost.Open(); 
      MessageBox.Show("Service Started!"); 
     } 

     private void button2_Click(object sender, EventArgs e) 
     { 
      if (myServiceHost.State != CommunicationState.Closed) 
      { 
       myServiceHost.Close(); 
       MessageBox.Show("Service Stopped!"); 
      } 
     } 
    } 
} 

ASP.net 클라이언트 코드

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using DuplexService; 
using System.ServiceModel; 

public partial class _Default : System.Web.UI.Page, ITemperatureCallback 
{ 
    static InstanceContext site = new InstanceContext(new _Default()); 
    static TemperatureClient proxy = new TemperatureClient(site); 

    public bool TempUpdate(double temp) 
    { 
     Response.Redirect("Temp dropped to {0} : " + temp); 
     return true; 
    } 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     proxy.RegisterForTempDrops(); 
    } 
} 

당신은 사용

<?xml version="1.0"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=169433 
    --> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <wsDualHttpBinding> 
     <binding name="WSDualHttpBinding_ITemperature" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" 
      textEncoding="utf-8" useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" /> 
      <security mode="Message"> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </wsDualHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:5050/duplexservice" binding="wsDualHttpBinding" 
     bindingConfiguration="WSDualHttpBinding_ITemperature" contract="DuplexService.ITemperature" 
     name="WSDualHttpBinding_ITemperature"> 
     <identity> 
      <userPrincipalName value="smdunk" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
</configuration> 
+0

여기와 같습니다. 그것은 콘솔에서 작동하지만 ASP.Net에서는 작동하지 않습니다. 당신은 그걸 작동시킬 수 있었습니까? 감사. – TTCG

답변

0

의 Web.config 코드

Response.Redirect("Temp dropped to {0} : " + temp); 

로 변경하십시오.

Response.Write("Temp dropped to {0} : " + temp); 
관련 문제