在F#中创建从ClientBase继承的WCF客户端

|| 我在此处的msdn站点上找到了以下代码: http://msdn.microsoft.com/en-us/library/ms733133.aspx#Y380
[System.ServiceModel.ServiceContractAttribute(Namespace=\"http://Microsoft.ServiceModel.Samples\", ConfigurationName=\"ICalculator\")]
public interface ICalculator
{
    [System.ServiceModel.OperationContractAttribute(Action=\"http://Microsoft.ServiceModel.Samples/ICalculator/Add\", ReplyAction=\"http://Microsoft.ServiceModel.Samples/ICalculator/AddResponse\")]
    double Add(double n1, double n2);

    [System.ServiceModel.OperationContractAttribute(Action=\"http://Microsoft.ServiceModel.Samples/ICalculator/Subtract\", ReplyAction=\"http://Microsoft.ServiceModel.Samples/ICalculator/SubtractResponse\")]
    double Subtract(double n1, double n2);

    [System.ServiceModel.OperationContractAttribute(Action=\"http://Microsoft.ServiceModel.Samples/ICalculator/Multiply\", ReplyAction=\"http://Microsoft.ServiceModel.Samples/ICalculator/MultiplyResponse\")]
    double Multiply(double n1, double n2);

    [System.ServiceModel.OperationContractAttribute(Action=\"http://Microsoft.ServiceModel.Samples/ICalculator/Divide\", ReplyAction=\"http://Microsoft.ServiceModel.Samples/ICalculator/DivideResponse\")]
    double Divide(double n1, double n2);
}

public interface ICalculatorChannel : ICalculator, System.ServiceModel.IClientChannel
{
}

public partial class CalculatorClient : System.ServiceModel.ClientBase<ICalculator>, ICalculator
{

    public CalculatorClient()
    {
    }

    public CalculatorClient(string endpointConfigurationName) : 
            base(endpointConfigurationName)
    {
    }

    public CalculatorClient(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public CalculatorClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public CalculatorClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress)
    {
    }

    public double Add(double n1, double n2)
    {
        return base.Channel.Add(n1, n2);
    }

    public double Subtract(double n1, double n2)
    {
        return base.Channel.Subtract(n1, n2);
    }

    public double Multiply(double n1, double n2)
    {
        return base.Channel.Multiply(n1, n2);
    }

    public double Divide(double n1, double n2)
    {
        return base.Channel.Divide(n1, n2);
    }
}
显然,这是msdn上举世闻名的WCF CalculatorService。我上面显示的代码是使用svcutil.exe生成的。但是,svcutil.exe不会生成F#代码,因此我正在尝试将CalculatorClient转换为F#(我可以很好地处理接口)。我将向您展示到目前为止我所拥有的,除了我仅完成了前三行并且无论如何都可能是错误的(我从装饰它的所有红色波浪状印象中得到了印象)。我完全被同时继承自基类和接口的方法所困扰。我不需要翻译整个类,只需翻译具有几个构造函数和一个接口方法的类,并且我确定我可以解决其余的问题。虽然,如果您想翻译整个内容以备后代使用,请放心。 谢谢, 鲍勃 编辑:这是我正在使用的界面。如果可以改进,请随时进行编辑。
[<ServiceContract>]  
type ICalculator =
  [<OperationContract>]
  abstract member Add: float*float -> float
  [<OperationContract>]
  abstract member Subtract: float*float -> float
  [<OperationContract>]
  abstract member Multiply: float*float -> float
  [<OperationContract>]
  abstract member Divide: float*float -> float
    
已邀请:
这是一个粗略的刺探:
type CalculatorClient =
    inherit System.ServiceModel.ClientBase<ICalculator>
    new() = 
        { inherit System.ServiceModel.ClientBase<ICalculator>() }
    new(name:string) = 
        { inherit System.ServiceModel.ClientBase<ICalculator>(name) }
    new(name:string, remoteAddress:string) = 
        { inherit System.ServiceModel.ClientBase<ICalculator>(name, remoteAddress) }
    new(name:string, remoteAddress:System.ServiceModel.EndpointAddress) = 
        { inherit System.ServiceModel.ClientBase<ICalculator>(name, remoteAddress) }
    new(binding:System.ServiceModel.Channels.Binding, remoteAddress) = 
        { inherit System.ServiceModel.ClientBase<ICalculator>(binding, remoteAddress) }
    member x.Add(n1,n2) = base.Channel.Add(n1,n2)
    member x.Subtract(n1,n2) = base.Channel.Subtract(n1,n2)
    member x.Multiply(n1,n2) = base.Channel.Multiply(n1,n2)
    member x.Divide(n1,n2) = base.Channel.Divide(n1,n2)
    interface ICalculator with
        // call into the methods on the class - these are *not* recursive
        member x.Add(n1,n2) = x.Add(n1,n2)
        member x.Subtract(n1,n2) = x.Subtract(n1,n2)
        member x.Multiply(n1,n2) = x.Multiply(n1,n2)
        member x.Divide(n1,n2) = x.Divide(n1,n2)
    

要回复问题请先登录注册