我使用SignalR,但我遇到了问题。有一个名为Discussion.when
数据插入,触发调用API服务
API服务中的代码
public async void Triger(int ID)
{
try
{
var hubConnection = new HubConnection("http://localhost:57278");
IHubProxy stockTickerHubProxy = hubConnection.CreateHubProxy("DiscussionHub");
await hubConnection.Start(new LongPollingTransport());
stockTickerHubProxy.Invoke("RefreshData", ID);
}
catch (Exception ex)
{
int i = 0;
}
}
但是它引发了以下错误
StatusCode:404,ReasonPhrase:'Not Found',版本:1.1,内容:
System.Net.Http.StreamContent,Headers:{X-SourceFiles: =?UTF-8 2 B 4 QzpcVXNlcnNcw7ZtZXJcRG9jdW1lbnRzXGFwY3Vyc1xhcGN1cnNcYXBjdXJzXERpc2N1c3Npb25IdWJcc2lnbmFsclxuZWdvdGlhdGU =?= 缓存控制:私人日期:2018年2月27日星期二17:40:20 GMT
服务器:Microsoft-IIS / 10.0 X-AspNet-版本:4.0.30319
X-Powered-By:ASP.NET Content-Length:3284 Content-Type: 为text / html;字符集= UTF-8}
,这是Hub类
public class DiscussionHub : Hub
{
public static object _lock = new object();
public static DiscussionsModel dataList = new DiscussionsModel();
public void RefreshData(int ID)
{
lock (_lock)
{
SubDiscussionModel sdm = new SubDiscussionModel();
DbDataContext db = new DbDataContext();
if (!dataList.subDiscussions.Any())
{
var discussion = (from q in db.Discussions
select new DiscussionsModel
{
id = q.id,
user = q.User,
discussionText = q.DiscussionText,
createdDate = q.CreatedDate,
viewCount = q.ViewCount,
shortTitle = q.ShortTitle,
isWantEmail = q.IsWantEmail,
status = q.Status,
}).Where(a => a.id == 1).FirstOrDefault();
DiscussionsModel data = discussion;
dataList = data;
}
else
{
SubDiscussion data = db.SubDiscussions.SingleOrDefault(ga => ga.id == ID);
sdm.id = data.id;
sdm.status = data.Status;
sdm.text = data.Text;
sdm.user = data.User;
sdm.createdDate = data.CreatedDate;
sdm.discussionId = data.DiscussionId;
dataList.subDiscussions.Add(sdm);
}
string viewName = @"~/Views/discussions/SubDiscussionListPartial.cshtml";
var discussionScreen = Helper.GetRazorViewAsString(dataList, viewName);
Clients.All.refreshData(discussionScreen);
}
}
}