WCF分布式开发常见错误解决(7):Cannot have two operations in the same contract
2009-04-04 19:45
711 查看
我们启动服务宿主程序的时候,有可能出现如下的无效操作异常,信息如下:
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);
}
重新编译运行代码即可。
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);
}
重新编译运行代码即可。
相关文章推荐
- WCF分布式开发常见错误解决(7):System.InvalidOperationException,Cannot have two operations in the same contract
- WCF分布式开发常见错误(27):Secure channel cannot be opened because security negotiation with the remote endpoint has failed
- WCF分布式开发常见错误解决(12):The server was unable to process the request,服务无法处理请求
- WCF分布式开发常见错误(28):The requested upgrade is not supported by...
- WCF分布式开发常见错误(8):不一致的访问性Inconsistent accessibility
- WCF分布式开发常见错误(26):Authentication failed because the remote party has closed the transport stream.
- WCF分布式开发常见错误(3):客户端调用服务出错:You have tried to create a channel to a service that does not support .Net Framing
- WCF分布式开发常见错误(22):The caller was not authenticated...如何在XP系统为WCF设置可信任的证书
- WCF分布式开发常见错误解决(9):无终结点监听,There was no endpoint listening at
- WCF分布式开发常见错误(22):The caller was not authenticated...如何在XP系统为WCF设置可信任的证书
- WCF分布式开发常见错误解决(1):添加服务引用出错
- WCF分布式开发常见错误(13):The transaction under which this method call was executing ,此方法调用的事务被异步中断
- WCF分布式开发常见错误(12):The server was unable to process the request,服务无法处理请求
- WCF分布式开发常见错误(15):Communication with the underlying transaction manager has failed.
- WCF分布式开发常见错误(24):Could not establish trust relationship for the SSL/TLS secure channel with authority(转)
- WCF分布式开发常见错误(12):The server was unable to process the request,服务无法处理请求
- WCF分布式开发常见错误(23):This could be due to the fact that the server certificate is not configured properly with HTTP.SYS
- WCF分布式开发常见错误(28):The requested upgrade is not supported by...
- WCF分布式开发常见错误(8):不一致的访问性Inconsistent accessibility
- WCF分布式开发常见错误(4):could not be found DataContract