使用 c# 使用 WSDL 代理 class

Consume WSDL proxy class using c#

我已经生成了一个代理class,但我不知道如何使用它。

我还实例化了 class 并访问了 class 但我不知道如何获得响应 我的访问代码 控制器 class 访问代理:

ProjectByElementsQuerySelectionByElements query = new 
   ProjectByElementsQuerySelectionByElements();
   
        

        ProjectByElementsQueryMessage_sync sync = new ProjectByElementsQueryMessage_sync{
            ProjectSelectionByElements = query

        };

代理肥皂class: 这是从 wsdl 文件自动生成的,是我想要使用的代理 class。 public 部分 class ProjectStatusByQueryResponse {

private ProjectLifeCycleStatusCode projectLifeCycleStatusCodeField;

private UPTODATEOUTOFDATE_UpToDatenessStatusCode schedulingUpToDatenessStatusCodeField;

private StartingStatusCode startingStatusCodeField;

private ProjectTaskLifeCycleStatusCode taskLifeCycleStatusCodeField;

private BlockingStatusCode taskBlockingStatusCodeField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ProjectLifeCycleStatusCode ProjectLifeCycleStatusCode {
    get {
        return this.projectLifeCycleStatusCodeField;
    }
    set {
        this.projectLifeCycleStatusCodeField = value;
    }
}

public partial class ProjectByElementsQuerySelectionByElements {

private ProjectSelectionByResponsibleUnitID[] selectionByResponsibleUnitIDField;

private ProjectSelectionByProjectId[] selectionByProjectIDField;

private ProjectSelectionByProjectName[] selectionByProjectNameField;

private ProjectSelectionByProjectType[] selectionByProjectTypeField;

private ProjectSelectionByCustomerID[] selectionByCustomerIDField;

private ProjectSelectionByRequestingUnitID[] selectionByRequestingUnitIDField;

private bool selectionByBillableIndicatorField;

private bool selectionByBillableIndicatorFieldSpecified;

private ProjectSelectionByInterCompanyIndicator[] selectionByIntercompanyIndicatorField;

private ProjectSelectionByResponsibleEmployeeID[] selectionByResponsibleEmployeeIDField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("SelectionByResponsibleUnitID", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ProjectSelectionByResponsibleUnitID[] SelectionByResponsibleUnitID {
    get {
        return this.selectionByResponsibleUnitIDField;
    }
    set {
        this.selectionByResponsibleUnitIDField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("SelectionByProjectID", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ProjectSelectionByProjectId[] SelectionByProjectID {
    get {
        return this.selectionByProjectIDField;
    }
    set {
        this.selectionByProjectIDField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("SelectionByProjectName", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ProjectSelectionByProjectName[] SelectionByProjectName {
    get {
        return this.selectionByProjectNameField;
    }
    set {
        this.selectionByProjectNameField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("SelectionByProjectType", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ProjectSelectionByProjectType[] SelectionByProjectType {
    get {
        return this.selectionByProjectTypeField;
    }
    set {
        this.selectionByProjectTypeField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("SelectionByCustomerID", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ProjectSelectionByCustomerID[] SelectionByCustomerID {
    get {
        return this.selectionByCustomerIDField;
    }
    set {
        this.selectionByCustomerIDField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("SelectionByRequestingUnitID", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ProjectSelectionByRequestingUnitID[] SelectionByRequestingUnitID {
    get {
        return this.selectionByRequestingUnitIDField;
    }
    set {
        this.selectionByRequestingUnitIDField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public bool SelectionByBillableIndicator {
    get {
        return this.selectionByBillableIndicatorField;
    }
    set {
        this.selectionByBillableIndicatorField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool SelectionByBillableIndicatorSpecified {
    get {
        return this.selectionByBillableIndicatorFieldSpecified;
    }
    set {
        this.selectionByBillableIndicatorFieldSpecified = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("SelectionByIntercompanyIndicator", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ProjectSelectionByInterCompanyIndicator[] SelectionByIntercompanyIndicator {
    get {
        return this.selectionByIntercompanyIndicatorField;
    }
    set {
        this.selectionByIntercompanyIndicatorField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("SelectionByResponsibleEmployeeID", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public ProjectSelectionByResponsibleEmployeeID[] SelectionByResponsibleEmployeeID {
    get {
        return this.selectionByResponsibleEmployeeIDField;
    }
    set {
        this.selectionByResponsibleEmployeeIDField = value;
    }
}

}

代理class文件添加到项目中,用于实例化代理class调用wcf服务。如果不明白这种方式调用wcf服务可以参考ServiceModel Metadata Utility Tool.

另外,您还可以通过添加服务引用来调用wcf服务。这是最简单的方法。右击项目,在add中selectaddservicereference,然后添加service reference。