WCF分布式开发常见错误解决(7):System.InvalidOperationException,Cannot have two operations in the same contract
2009-04-04 19:20
836 查看
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
我们启动服务宿主程序的时候,有可能出现如下的无效操作异常,信息如下:
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):Cannot have two operations in the same contract
- WCF分布式开发常见错误(4):The type or namespace name 'DataContract' could not be found DataContract找不到
- WCF分布式开发常见错误(14):无效的操作异常,At least one operation on the ...
- “System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 错误
- Fix: "Sys.InvalidOperationException: Two components with the same id
- 线程使用中常见的错误-“System.InvalidOperationException”线程间操作无效: 从不是创建控件“ ”的线程访问它。
- 【ASP.NET 问题】System.InvalidOperationException: 对象的当前状态使该操作无效 【大量表单数据提交】错误解决
- 异常:System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms 这个实现是不是Windows平台FIPS验证的加密算法。解决方法
- idea 错误 Two modules in a project cannot share the same content root
- jstl学习常见错误一: The absolute uri: http://java.sun.com/jst/core cannot be resolved in either web.xml or the jar files deployed with
- InvalidDataAccessApiUsageException 和 Write operations are not allowed in read-only mode 解决方法
- 解决Eclipse导入项目是提示错误:Some projects cannot be imported because they already exist in the workspace
- 我的Java开发学习之旅------>Workspace in use or cannot be created, choose a different one.--错误解决办法
- Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity解决方法
- 发生了 System.InvalidOperationException,mob短信模块开发,极光开发配置!!
- 开发常见错误解决(5)WSE3.0未处理的SoapHeaderException,未处理的SoapHeader异常
- WCF分布式开发常见错误(16):The Transaction has aborted,事务已经被中断
- System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: 超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
- 解决错误 Some projects cannot be imported because they already exist in the workspace
- 解决Eclipse导入项目是提示错误:Some projects cannot be imported because they already exist in the workspace