生成没有servicemodel元数据的SOAP客户端

时间:2014-05-23 08:29:21

标签: c# .net wcf soap

我的客户端有一个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#库的一部分。

如何使用此界面生成客户端?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

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;
    }
}

}