我尝试按照本教程On MSDN了解有关工作流服务及其工作原理的更多信息。现在我可能已经疯了,但我在教程的客户端部分遇到了问题(我很想责怪教程而不是我自己这个问题)。我在StartOrderClient初始化和AddItemClient上遇到了引用错误。这只是教程中稍微不完整的一步,还是我遗漏了什么?
我提前非常感谢你。
以下是我的订单客户端控制台计划
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Activities;
namespace OrderClient.OrderService
{
class Program
{
static void Main(string[] args)
{
// Send initial message to start the workflow service
Console.WriteLine("Sending start message");
StartOrderClient startProxy = new StartOrderClient();
string orderId = startProxy.StartOrder("Kim Abercrombie");
// The workflow service is now waiting for the second message to be sent
Console.WriteLine("Workflow service is idle...");
Console.WriteLine("Press [ENTER] to send an add item message to reactivate the workflow service...");
Console.ReadLine();
// Send the second message
Console.WriteLine("Sending add item message");
AddItemClient addProxy = new AddItemClient();
AddItem item = new AddItem();
item.p_itemId = "Zune HD";
item.p_orderId = orderId;
string orderResult = addProxy.AddItem(item);
Console.WriteLine("Service returned: " + orderResult);
}
}
}
以下是错误。 StartOrderClient和AddItemClient,我不相信会在教程中定义。
类型或命名空间名称' StartOrderClient'找不到(你错过了使用指令或汇编引用吗?)
类型或命名空间名称' AddItemClient'找不到(你错过了使用指令或汇编引用吗?)
答案 0 :(得分:0)
要解决此错误,请打开Service1.xamlx文件。点击ReceiveStartOrder
并将ServiceContractName
属性更改为{http://tempuri.org/}IStartOrder
(默认情况下通常为{http://tempuri.org/}IService}
)。对ReceiveAddItem
活动(IAddItem
)执行相同的操作。
重建解决方案。在控制台项目中,右键单击OrderService
服务引用并进行更新。
注意:本教程充满了错误,我仍在努力解决它。一旦我成功完成并记录了缺失的步骤和不准确之处,我将更新此答案,并可能包含一篇博客文章链接和修订过的教程。
对于尝试执行本教程的任何人,更好的选择是遵循this updated tutorial。
答案 1 :(得分:0)
我将此代码用于main方法
static void Main(string[] args)
{
// Send initial message to start the workflow service
Console.WriteLine("Sending start message");
ServiceClient proxy = new ServiceClient();
string orderId = proxy.StartOrder("Kim Abercrombie");
// The workflow service is now waiting for the second message to be sent
Console.WriteLine("Workflow service is idle...");
Console.WriteLine("Press [ENTER] to send an add item message to reactivate the workflow service...");
Console.ReadLine();
// Send the second message
Console.WriteLine("Sending add item message");
AddItem item = new AddItem();
item.p_itemId = "Zune H";
item.p_orderId = orderId;
string orderResult = proxy.AddItem(item);
Console.WriteLine("Service returned: " + orderResult);
}