首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单个操作的WSDL

单个操作的WSDL
EN

Stack Overflow用户
提问于 2019-05-10 09:36:33
回答 2查看 35关注 0票数 0

我从我的客户那里收到了一个wsdl,用来调用他们在WCF中内置的web服务。这个wsdl有n个操作,这些操作对于我的目的来说实际上并不是必需的。相反,我只需要调用2-3个方法。有没有可能让我拆分wsdl或调整wsdl使其只适用于我的方法?

EN

回答 2

Stack Overflow用户

发布于 2019-05-10 19:25:26

尽管可以编辑wsdl并删除您不打算使用的操作,但提供默认实现可能要容易得多。例如,你可以使用throw new NotImplementedException()作为方法体。这有一个很好的副作用,当调用代码时无意中调用了您不打算使用的方法时,会抛出异常。

票数 0
EN

Stack Overflow用户

发布于 2019-05-17 10:08:29

不知道如何使用wsdl来满足您的需求。但是,在通过此wsdl添加服务引用之后,您可以删除不需要的方法。

例如,在我添加了引用之后,我有了ICalculatorService服务契约和CalculatorServiceClient服务代理。

代码语言:javascript
复制
public interface ICalculatorService  {

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Add", ReplyAction="http://tempuri.org/ICalculatorService/AddResponse")]
    double Add(double a, double b);



    //[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICalculatorService/Substract", ReplyAction="http://tempuri.org/ICalculatorService/SubstractResponse")]
    //double Substract(double a, double b);

}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface ICalculatorServiceChannel : consoleClient.CalculatorClient.ICalculatorService, System.ServiceModel.IClientChannel {
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class CalculatorServiceClient : System.ServiceModel.ClientBase<consoleClient.CalculatorClient.ICalculatorService>, consoleClient.CalculatorClient.ICalculatorService {

    public CalculatorServiceClient() {
    }

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

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

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

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

    public double Add(double a, double b) {
        return base.Channel.Add(a, b);
    }



    //public double Substract(double a, double b) {
    //    return base.Channel.Substract(a, b);
    //}


}

如果我不需要Substract方法,我可以在ICalculatorService和CalculatorServiceClient中注释掉Substract方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56069616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档