如果先关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."
浙公网安备 33010602011771号