我从我的客户那里收到了一个wsdl,用来调用他们在WCF中内置的web服务。这个wsdl有n个操作,这些操作对于我的目的来说实际上并不是必需的。相反,我只需要调用2-3个方法。有没有可能让我拆分wsdl或调整wsdl使其只适用于我的方法?
发布于 2019-05-10 19:25:26
尽管可以编辑wsdl并删除您不打算使用的操作,但提供默认实现可能要容易得多。例如,你可以使用throw new NotImplementedException()作为方法体。这有一个很好的副作用,当调用代码时无意中调用了您不打算使用的方法时,会抛出异常。
发布于 2019-05-17 10:08:29
不知道如何使用wsdl来满足您的需求。但是,在通过此wsdl添加服务引用之后,您可以删除不需要的方法。
例如,在我添加了引用之后,我有了ICalculatorService服务契约和CalculatorServiceClient服务代理。
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方法。
https://stackoverflow.com/questions/56069616
复制相似问题