生成没有服务模型元数据的SOAP客户端

本文关键字:元数据 SOAP 客户端 模型 服务 | 更新日期: 2023-09-27 18:04:40

我的客户端有一个WCF SOAP服务,我必须创建一个客户端来连接它。

他给我发了这个:

namespace ServiceWs.Contract
{
    [ServiceContract(Namespace = Constants.Namespace)]
    public interface IServerWs : IDisposable
    {
        #region Methods
        [OperationContract]
        ServerOpenSession OpenSession(RequestedOpenSession openingInfo);
        [OperationContract]
        ServedBuffer GetBuffer(ServerSessionRef sessionRef, RequestedBuffer requestedBuffer);
        [OperationContract]
        ServerCloseSession CloseSession(RequestedCloseSession closingInfo);
        #endregion Methods
    }
}

是c#库的一部分。

如何使用这个接口生成客户端?

生成没有服务模型元数据的SOAP客户端

您还需要服务提供者的URL请访问下面的链接这是http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/four-steps-to-create-first-wcf-service-for-beginners/

VasFannel,我通过做你的接口的一些虚拟实现生成以下客户端:(如何?:我创建虚拟实现,添加并托管它,并为它创建一个客户端。然后添加一个服务引用到另一个项目,这自动为我生成了以下内容。

namespace ActivityLibrary1.ServiceReference1 {
using System.Runtime.Serialization;
using System;

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="RequestedOpenSession", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
[System.SerializableAttribute()]
public partial class RequestedOpenSession : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
    [System.NonSerializedAttribute()]
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
        get {
            return this.extensionDataField;
        }
        set {
            this.extensionDataField = value;
        }
    }
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ServerOpenSession", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
[System.SerializableAttribute()]
public partial class ServerOpenSession : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
    [System.NonSerializedAttribute()]
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
        get {
            return this.extensionDataField;
        }
        set {
            this.extensionDataField = value;
        }
    }
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ServerSessionRef", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
[System.SerializableAttribute()]
public partial class ServerSessionRef : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
    [System.NonSerializedAttribute()]
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
        get {
            return this.extensionDataField;
        }
        set {
            this.extensionDataField = value;
        }
    }
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="RequestedBuffer", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
[System.SerializableAttribute()]
public partial class RequestedBuffer : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
    [System.NonSerializedAttribute()]
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
        get {
            return this.extensionDataField;
        }
        set {
            this.extensionDataField = value;
        }
    }
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ServedBuffer", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
[System.SerializableAttribute()]
public partial class ServedBuffer : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
    [System.NonSerializedAttribute()]
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
        get {
            return this.extensionDataField;
        }
        set {
            this.extensionDataField = value;
        }
    }
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="RequestedCloseSession", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
[System.SerializableAttribute()]
public partial class RequestedCloseSession : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
    [System.NonSerializedAttribute()]
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
        get {
            return this.extensionDataField;
        }
        set {
            this.extensionDataField = value;
        }
    }
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ServerCloseSession", Namespace="http://schemas.datacontract.org/2004/07/WcfServiceLibrary1")]
[System.SerializableAttribute()]
public partial class ServerCloseSession : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
    [System.NonSerializedAttribute()]
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
        get {
            return this.extensionDataField;
        }
        set {
            this.extensionDataField = value;
        }
    }
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged(string propertyName) {
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) {
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="MyTest", ConfigurationName="ServiceReference1.IServerWs")]
public interface IServerWs {
    [System.ServiceModel.OperationContractAttribute(Action="MyTest/IServerWs/OpenSession", ReplyAction="MyTest/IServerWs/OpenSessionResponse")]
    ActivityLibrary1.ServiceReference1.OpenSessionResponse OpenSession(ActivityLibrary1.ServiceReference1.OpenSessionRequest request);
    [System.ServiceModel.OperationContractAttribute(Action="MyTest/IServerWs/OpenSession", ReplyAction="MyTest/IServerWs/OpenSessionResponse")]
    System.Threading.Tasks.Task<ActivityLibrary1.ServiceReference1.OpenSessionResponse> OpenSessionAsync(ActivityLibrary1.ServiceReference1.OpenSessionRequest request);
    [System.ServiceModel.OperationContractAttribute(Action="MyTest/IServerWs/GetBuffer", ReplyAction="MyTest/IServerWs/GetBufferResponse")]
    ActivityLibrary1.ServiceReference1.GetBufferResponse GetBuffer(ActivityLibrary1.ServiceReference1.GetBufferRequest request);
    [System.ServiceModel.OperationContractAttribute(Action="MyTest/IServerWs/GetBuffer", ReplyAction="MyTest/IServerWs/GetBufferResponse")]
    System.Threading.Tasks.Task<ActivityLibrary1.ServiceReference1.GetBufferResponse> GetBufferAsync(ActivityLibrary1.ServiceReference1.GetBufferRequest request);
    [System.ServiceModel.OperationContractAttribute(Action="MyTest/IServerWs/CloseSession", ReplyAction="MyTest/IServerWs/CloseSessionResponse")]
    ActivityLibrary1.ServiceReference1.CloseSessionResponse CloseSession(ActivityLibrary1.ServiceReference1.CloseSessionRequest request);
    [System.ServiceModel.OperationContractAttribute(Action="MyTest/IServerWs/CloseSession", ReplyAction="MyTest/IServerWs/CloseSessionResponse")]
    System.Threading.Tasks.Task<ActivityLibrary1.ServiceReference1.CloseSessionResponse> CloseSessionAsync(ActivityLibrary1.ServiceReference1.CloseSessionRequest request);
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="OpenSession", WrapperNamespace="MyTest", IsWrapped=true)]
public partial class OpenSessionRequest {
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="MyTest", Order=0)]
    public ActivityLibrary1.ServiceReference1.RequestedOpenSession openingInfo;
    public OpenSessionRequest() {
    }
    public OpenSessionRequest(ActivityLibrary1.ServiceReference1.RequestedOpenSession openingInfo) {
        this.openingInfo = openingInfo;
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="OpenSessionResponse", WrapperNamespace="MyTest", IsWrapped=true)]
public partial class OpenSessionResponse {
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="MyTest", Order=0)]
    public ActivityLibrary1.ServiceReference1.ServerOpenSession OpenSessionResult;
    public OpenSessionResponse() {
    }
    public OpenSessionResponse(ActivityLibrary1.ServiceReference1.ServerOpenSession OpenSessionResult) {
        this.OpenSessionResult = OpenSessionResult;
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="GetBuffer", WrapperNamespace="MyTest", IsWrapped=true)]
public partial class GetBufferRequest {
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="MyTest", Order=0)]
    public ActivityLibrary1.ServiceReference1.ServerSessionRef sessionRef;
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="MyTest", Order=1)]
    public ActivityLibrary1.ServiceReference1.RequestedBuffer requestedBuffer;
    public GetBufferRequest() {
    }
    public GetBufferRequest(ActivityLibrary1.ServiceReference1.ServerSessionRef sessionRef, ActivityLibrary1.ServiceReference1.RequestedBuffer requestedBuffer) {
        this.sessionRef = sessionRef;
        this.requestedBuffer = requestedBuffer;
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="GetBufferResponse", WrapperNamespace="MyTest", IsWrapped=true)]
public partial class GetBufferResponse {
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="MyTest", Order=0)]
    public ActivityLibrary1.ServiceReference1.ServedBuffer GetBufferResult;
    public GetBufferResponse() {
    }
    public GetBufferResponse(ActivityLibrary1.ServiceReference1.ServedBuffer GetBufferResult) {
        this.GetBufferResult = GetBufferResult;
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="CloseSession", WrapperNamespace="MyTest", IsWrapped=true)]
public partial class CloseSessionRequest {
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="MyTest", Order=0)]
    public ActivityLibrary1.ServiceReference1.RequestedCloseSession closingInfo;
    public CloseSessionRequest() {
    }
    public CloseSessionRequest(ActivityLibrary1.ServiceReference1.RequestedCloseSession closingInfo) {
        this.closingInfo = closingInfo;
    }
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="CloseSessionResponse", WrapperNamespace="MyTest", IsWrapped=true)]
public partial class CloseSessionResponse {
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="MyTest", Order=0)]
    public ActivityLibrary1.ServiceReference1.ServerCloseSession CloseSessionResult;
    public CloseSessionResponse() {
    }
    public CloseSessionResponse(ActivityLibrary1.ServiceReference1.ServerCloseSession CloseSessionResult) {
        this.CloseSessionResult = CloseSessionResult;
    }
}

}