我是靠谱客的博主 忧郁黑米,最近开发中收集的这篇文章主要介绍WCF分布式开发常见错误解决(7):System.InvalidOperationException,Cannot have two operations in the same contract,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Posted on 2009-04-04 19:45 Frank Xu Lei 阅读(467) 评论(0)   编辑 收藏 网摘 所属分类: WCF分布式开发常见错误

   我们启动服务宿主程序的时候,有可能出现如下的无效操作异常,信息如下:
Cannot have two operations in the same contract with the same name, methods SayHello and SayHello in type WCFService.IWCFService violate this rule. You can change the name of one of the operations by changing the method name or by using the Name property of OperationContractAttribute.异常信息截图:

    原因:这个是由于服务契约里定义了定义了两个相同名称的操作契约。

解决办法:

1.重新定义操作契约的名称,使两者不同;

2.或者使用操作契约的名称属性,实例代码如下:

     // 1.服务契约,操作契约重载
    [ServiceContract(Namespace  =   " http://www.cnblogs.com/frank_xl/ " )]
    
public   interface  IWCFService
    {
        
// 操作契约
        [OperationContract(Name  =   " SayHello1 " )]
        
string  SayHello();
        
// 操作契约
        [OperationContract(Name  =   " SayHello2 " )]
        
string  SayHello( string  name);
        
// 操作契约
        [OperationContract(Name  =   " SayHello3 " )]
        
string  SayHello( string  firstName,  string  lastName);

    }

 

 重新编译运行代码即可。


 

【老徐的博客】

【作者】:Frank Xu Lei

【地址】:http://www.cnblogs.com/frank_xl/archive/2009/04/04/1429551.html

 

最后

以上就是忧郁黑米为你收集整理的WCF分布式开发常见错误解决(7):System.InvalidOperationException,Cannot have two operations in the same contract的全部内容,希望文章能够帮你解决WCF分布式开发常见错误解决(7):System.InvalidOperationException,Cannot have two operations in the same contract所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(64)

相关文章

Flex连接wcf返回List<object>数据
Flex连接wcf返回List数据

评论列表共有 0 条评论