WCF& Azure:在已实施的合同列表中找不到合同名称

发布于 2024-12-08 19:26:40 字数 3243 浏览 0 评论 0原文

我正在学习如何使用 WCF(Windows Communication Foundation)进行辅助角色通信。

我完全按照此链接中显示的演示进行操作:工人角色沟通

但是当我编写程序时,我收到 InvalidOperation 异常:

在以下位置找不到合约名称“WcfServiceLibrary1.IService1” 服务实施的合同清单 'System.ServiceModel.ServiceHost'。

这是我的堆栈跟踪:

未处理的异常:System.InvalidOperationException:合同 在列表中找不到名称“WcfServiceLibrary1.IService1” 服务执行的合同 '系统.ServiceModel.ServiceHost'。在 System.ServiceModel.ServiceHost.ValidateContractType(类型 ImplementedContract、ReflectedAndBehaviorContractCollection ReflectedAndBehaviorContracts)位于 System.ServiceModel.ServiceHost.AddServiceEndpoint(类型 实现Contract、Binding绑定、Uri地址、UrilistenUri)
在 System.ServiceModel.ServiceHost.AddServiceEndpoint(类型 已实现的Contract、Binding 绑定、Uri 地址)位于 System.ServiceModel.ServiceHost.AddServiceEndpoint(类型 实现Contract、Binding绑定、字符串地址、Uri(listenUri)
在 System.ServiceModel.ServiceHost.AddServiceEndpoint(类型 已实现的Contract、Binding绑定、字符串地址)位于 WorkerRole1.WorkerRole.StartService1() 中 C:\Users\veda\documents\Visual Studio 2010\Projects\roleToRoleCommInternalEndPt\WorkerRole1\WorkerRole.cs:行 53 在 WorkerRole1.WorkerRole.Run() 中 C:\Users\veda\documents\Visual Studio 2010\Projects\roleToRoleCommInternalEndPt\WorkerRole1\WorkerRole.cs:行 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 回调、对象状态、布尔值 忽略SyncCtx)在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、对象状态)位于 System.Threading.ThreadHelper.ThreadStart()

辅助角色内的代码:

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);


    }
}

谁能告诉我如何解决这个问题。

I am learning about how to do worker role communication using WCF (Windows Communication Foundation).

I exactly followed the demo shown at this link: Worker Role Communication

But when I the program, I am getting an InvalidOperation Exception:

The contract name 'WcfServiceLibrary1.IService1' could not be found in
the list of contracts implemented by the service
'System.ServiceModel.ServiceHost'.

Here is my Stack Trace:

Unhandled Exception: System.InvalidOperationException: The contract
name 'WcfServiceLibrary1.IService1' could not be found in the list of
contracts implemented by the service
'System.ServiceModel.ServiceHost'. at
System.ServiceModel.ServiceHost.ValidateContractType(Type
implementedContract, ReflectedAndBehaviorContractCollection
reflectedAndBehaviorContracts) at
System.ServiceModel.ServiceHost.AddServiceEndpoint(Type
implementedContract, Binding binding, Uri address, Uri listenUri)
at System.ServiceModel.ServiceHost.AddServiceEndpoint(Type
implementedContract, Binding binding, Uri address) at
System.ServiceModel.ServiceHost.AddServiceEndpoint(Type
implementedContract, Binding binding, String address, Uri listenUri)
at System.ServiceModel.ServiceHost.AddServiceEndpoint(Type
implementedContract, Binding binding, String address) at
WorkerRole1.WorkerRole.StartService1() in
C:\Users\veda\documents\visual studio
2010\Projects\roleToRoleCommInternalEndPt\WorkerRole1\WorkerRole.cs:line
53 at WorkerRole1.WorkerRole.Run() in
C:\Users\veda\documents\visual studio
2010\Projects\roleToRoleCommInternalEndPt\WorkerRole1\WorkerRole.cs:line
26 at
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRoleInternal()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRole()
at
Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.b__1()
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx) at
System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state) at
System.Threading.ThreadHelper.ThreadStart()

The Code inside the worker role:

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);
        }                               
    }

The WCF code:

    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);


    }
}

Can anyone tell me how to solve this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有一腔孤勇 2024-12-15 19:26:40

您的第一个问题是您告诉 ServiceHost 托管 ServiceHost,而不是您的服务类。此行没有任何意义:

this.serviceHost = new ServiceHost(typeof(ServiceHost));  

您需要将其替换为:

this.serviceHost = new ServiceHost(typeof(Service1)); 

并添加

public class Service1: IService1
{
     public string SayHello(string value) { return string.Format("Hello from {0}", value); }
}

这个问题的答案中的托管示例都是基于代码的,并且非常简单。使用它作为参考。

Your first problem is that you told ServiceHost to host ServiceHost, instead of your service class. This line doesn't make any sense:

this.serviceHost = new ServiceHost(typeof(ServiceHost));  

You need to replace it with:

this.serviceHost = new ServiceHost(typeof(Service1)); 

and add

public class Service1: IService1
{
     public string SayHello(string value) { return string.Format("Hello from {0}", value); }
}

The hosting example in the answer to this question is all code based and as simple as it gets. Use it for a reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文