[英]How to use web service from a .NET Console
我成功地從數據庫表中讀取了我的記錄,並且我將信息放在List中,其類型是ClaimComment
(用於映射的類),因為我需要將信息放在新的數據庫表中。
using (var dbContext = new OldDbContextEntities())
{
var claimComments = dbContext.R_ClaimHistory.ToList();
var newDbContextClaimCommentsToSend = new List<ClaimComment>();
foreach (var claimComment in claimComments)
{
var claimCommentToMigrate = new ClaimComment()
{
ClaimId = (int)claimComment.IdClaim,
Comment = claimComment.HistClaimDescription,
DateCreated = claimComment.DateCreated,
UserCreated = (int)claimComment.IdUserCreated
};
newDbContextClaimCommentsToSend.Add(claimCommentToMigrate);
}
// continues below...
我需要使用Web Api將信息放在database2表中。 我是這樣開始的:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:54957/api/EntityMigration");
var response = client.PostAsync("api/claimComment", newDbContextClaimCommentsToSend);
}
但是我收到了錯誤:
錯誤CS1503參數2:無法從'System.Collections.Generic.List'轉換為'System.Net.Http.HttpContent'
HttpClient文檔非常清楚,第二個參數應該是一個HttpContent實例...考慮一下ObjectContent類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.