我有一个MVC2应用程序。基本上,在我的Bill视图中,我希望用户单击“Request Bill”并调用WCF服务。该服务然后返回一个回叫的欠款。我有两个问题。调用WCF双工服务的ASP.NET MVC2应用程序
- 来自客户端的双工方法回调不会执行或不会被调用。这是发生在一起的。有时会被调用,有时不会
- 第二个问题是,无论是否执行回调方法,页面或应用程序在返回视图后不久(2-3秒内)都会关闭。
我认为,我有以下:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Bill
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Bill Summary:</h2>
<td>
<%: ViewData["ProcessingMessage"] %>
</td>
<table>
<tr>
<th>
Username:
</th>
<th>
Total Number of Calls:
</th>
<th>
Amount to be Paid:
</th>
<th> </th>
</tr>
<td>
<%: ViewData["Username"] %>
</td>
<td>
<%: ViewData["CallsCount"] %>
</td>
<td>
<%: ViewData["TotalAmount"] %>
</td>
</table>
</asp:Content>
在我的控制器,我有以下方法:
public class TelephoneController : Controller
{
BillingCallback proxy = new BillingCallback();
public ActionResult Bill()
{
ViewData["ProcessingMessage"] = "Processing Request.....";
proxy.CallService(User.Identity.Name);
return View();
}
}
我创建回调的类:
public class BillController : Controller
{
private const double amountPerCall = 0.25;
public double calcBill()
{
double total = amountPerCall;
Log p = new Log();
return total;
}
public ActionResult Index()
{
return View();
}
}
现在服务:
[ServiceContract(CallbackContract = typeof(IBillCallBack))]
public interface IBill
{
[OperationContract(IsOneWay = true)]
void GetBilling(string username);
}
public interface IBillCallBack
{
[OperationContract(IsOneWay = true)]
void CalculateBilling(string message);
}
[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple)]
class Bill : IBill
{
public void GetBilling(string username)
{
IBillCallBack callback = OperationContext.Current.GetCallbackChannel<IBillCallBack>();
ThreadPool.QueueUserWorkItem(new WaitCallback(SendOperationToClient), callback);
}
public void SendOperationToClient(object stateinfo)
{
IBillCallBack callback;
callback = stateinfo as IBillCallBack;
string s = Thread.CurrentThread.ManagedThreadId.ToString();
callback.CalculateBilling("username");
}
}
任何想法?
1+好描述 – Aliostad 2010-10-02 15:46:26
你使用哪种绑定? HTTP还是TCP?目前为 – Aliostad 2010-10-02 15:49:27
,netTcpBinding。我也试过用wsDualHttpBinding - 发生同样的行为 – Mage 2010-10-02 16:37:57