【发布时间】:2011-12-01 23:59:28
【问题描述】:
我正在学习如何使用 WCF (Windows Communication Foundation) 进行辅助角色通信。
我完全按照此链接中显示的演示:Worker Role Communication
但是当我执行程序时,我得到了一个 InvalidOperation 异常:
在中找不到合同名称“WcfServiceLibrary1.IService1” 服务实施的合同清单 'System.ServiceModel.ServiceHost'。
这是我的堆栈跟踪:
未处理的异常:System.InvalidOperationException:合同 在列表中找不到名称“WcfServiceLibrary1.IService1” 服务执行的合同 'System.ServiceModel.ServiceHost'。在 System.ServiceModel.ServiceHost.ValidateContractType(类型 实施合同,反射和行为合同集合 反射和行为合同)在 System.ServiceModel.ServiceHost.AddServiceEndpoint(类型 实现Contract,Binding绑定,Uri地址,Uri listenUri)
在 System.ServiceModel.ServiceHost.AddServiceEndpoint(类型 实现的Contract,Binding绑定,Uri地址)在 System.ServiceModel.ServiceHost.AddServiceEndpoint(类型 已实现Contract、Binding 绑定、String 地址、Uri listenUri)
在 System.ServiceModel.ServiceHost.AddServiceEndpoint(类型 实施合同,绑定绑定,字符串地址)在 WorkerRole1.WorkerRole.StartService1() 在 C:\Users\veda\documents\visual studio 2010\Projects\roleToRoleCommInternalEndPt\WorkerRole1\WorkerRole.cs:line 53 在 WorkerRole1.WorkerRole.Run() 中 C:\Users\veda\documents\visual studio 2010\Projects\roleToRoleCommInternalEndPt\WorkerRole1\WorkerRole.cs:line 26 在 Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRoleInternal() 在 Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRole()
在 Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.b__1() 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、对象状态、布尔值 ignoreSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、对象状态)在 System.Threading.ThreadHelper.ThreadStart()
worker 角色内部的代码:
private void StartService1()
{
Trace.TraceInformation("Starting service 1 host...");
this.serviceHost = new ServiceHost(typeof(ServiceHost));
var binding = new NetTcpBinding(SecurityMode.None);
serviceHost.AddServiceEndpoint(typeof(WcfServiceLibrary1.IService1),
binding,
string.Format("net.tcp://{0}/Service1",
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["RoleToRole"].IPEndpoint));
WorkerRole.factory = new ChannelFactory<IService1>(binding);
try
{
serviceHost.Open();
Trace.TraceInformation("Service Host started successfully.");
}
catch (Exception e)
{
Trace.TraceError("There is an error {0}:", e.Message);
}
}
WCF 代码:
namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string SayHello(string value);
}
}
谁能告诉我如何解决这个问题。
【问题讨论】: