以下是WCF服务端的服务契约
客户端采用VS自带的导入工具,虽然可以使用生成的代理和契约,但还需要进行修改,使客户端代码支持操作重载。方法是将导入的代理和契约的方法名修改为重载的名称,并确保代理能够使用重载方法调用内部代理。
最后,在客户端使用导入契约的Name属性,指定别名并重载方法,使他与导入的操作名保持一致。如下图:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute
public interface IService1
{
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public interface IService1Channel : IService1, System.ServiceModel.IClientChannel
{
}
public interface IService1Channel : IService1, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttri
bute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class Service1Client : System.ServiceModel.ClientBase, IService1
{
public Service1Client()
{
}
public Service1Client(string endpointConfigurationNam
e) :
base(endpointConfigurationNam
e)
{
}
public Service1Client(string endpointConfigurationNam
e, string remoteAddress) :
base(endpointConfigurationNam
e, remoteAddress)
{
}
public Service1Client(string endpointConfigurationNam
e, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationNam
e, remoteAddress)
{
}
public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public int Add(int arg1, int arg2)
{
return base.Channel.Add(arg1, arg2);
}
public string Add(string arg1, string arg2)
{
return base.Channel.Add(arg1, arg2);
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class Service1Client : System.ServiceModel.ClientBase, IService1
{
}