如果先关service再关client
那么client的channel.Close()会报异常:
“The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.”
如果还未启动service就打开client
则client的channel.Open()会报异常:
“The endpoint was not found. Please ensure that you can connect to the internet using HTTP port 80 and TCP port 808.”
Client与Service两边的属性的Namespace不一致
例如:
Client端:
public interface IEchoContract
{
[OperationContract]
String Echo(string text);
}
Server端:
[ServiceContract(Name = "IEchoContract", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/Echo")]
public interface IEchoContract
{
[OperationContract]
String Echo(string text);
}
在Client执行方法channel.Echo(input)的时候会报异常:
"The message with Action 'http://samples.microsoft.com/ServiceModel/Relay/IEchoContract/Echo' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)."
避免Contract和Behavior的paste© error
如果一个该用ServiceBehavior的地方用了ServiceContract,例如:
[ServiceContract(Name = "IEchoContract", Namespace = http://samples.microsoft.com/ServiceModel/Relay/)]
public class EchoService : IEchoContract
{
public string Echo(string text)
{
Console.WriteLine("Echoing: {0}", text);
return text;
}
}
则在new一个host的时候,ServiceHost host = new ServiceHost(typeof(EchoService), address); // 会抛出异常
异常信息:
"The service class of type Microsoft.ServiceBus.Samples.EchoService both defines a ServiceContract and inherits a ServiceContract from type Microsoft.ServiceBus.Samples.IEchoContract. Contract inheritance can only be used among interface types. If a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute. Consider moving the ServiceContractAttribute on type Microsoft.ServiceBus.Samples.IEchoContract to a separate interface that type Microsoft.ServiceBus.Samples.IEchoContract implements."
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架