C# 如何向只接受C中一个参数的webservice方法发送参数#

C# 如何向只接受C中一个参数的webservice方法发送参数#,c#,web-services,asmx,C#,Web Services,Asmx,一般来说,我不熟悉Web服务。我正在尝试向rmc服务CreateCar添加4个参数,并尝试在我的Webservices.cs文件中这样做。不幸的是,CreateCar方法只接受1个参数(请求)。这段代码的大部分基于接受所有参数的类似过程 我要打的电话是rmcService.CreateCar public bool CreateCar(string url, string viewedUserType, string userName, string accounts, string c

一般来说,我不熟悉Web服务。我正在尝试向rmc服务CreateCar添加4个参数,并尝试在我的Webservices.cs文件中这样做。不幸的是,CreateCar方法只接受1个参数(请求)。这段代码的大部分基于接受所有参数的类似过程

我要打的电话是rmcService.CreateCar

    public bool CreateCar(string url, string viewedUserType, string userName, string accounts, string carName)
    {
        bool returnValue = false;

        try
        {
            if (accounts.Length != 9)
            {
                if (accounts.Length == 8)
                {
                    accounts = accounts + "0";
                }
                else
                {
                    throw new ApplicationException("Invalid length for Account #");
                }
            }

            // Initialize web service object
            relationshipmgmtcentersvcdev.RmcService rmcService = new relationshipmgmtcentersvcdev.RmcService();
            rmcService.Url = url;

            // Attach credentials
            rmcService.Credentials = _Credentials;

            // Connection pooling
            rmcService.ConnectionGroupName = _Credentials.UserName.ToString();
            rmcService.UnsafeAuthenticatedConnectionSharing = true;

            // Hard coding View User Type as None
            viewedUserType = "None";

            // Call to create CAR - Client Account Relation
            rmcService.CreateCar(userName, viewedUserType, accounts, carName); 
            returnValue = true;
        }
        catch (Exception ex)
        {
            System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog("Application");
            eventLog.Source = "UAccCompWrapper";
            eventLog.WriteEntry("Error in CreateCar Method: " + ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
        }

        return returnValue;
    }
我收到的错误是CreateCar方法没有重载,它有4个参数(这很有意义)。我只是想说明我想做什么。这个方法看起来只需要一个参数

这是参考文件的一个片段,其中包含我发现的相关信息。似乎我需要使用参数创建BaseServiceRequest,但我不确定如何创建

  /// <remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://relationshipmgmtcenter.hfg.com/services/IRmcService/CreateCar", RequestNamespace="http://relationshipmgmtcenter.hfg.com/services/", ResponseNamespace="http://relationshipmgmtcenter.hfg.com/services/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public void CreateCar([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] CreateCarServiceRequest request) {
        this.Invoke("CreateCar", new object[] {
                    request});
    }

    /// <remarks/>
    public void CreateCarAsync(CreateCarServiceRequest request) {
        this.CreateCarAsync(request, null);
    }

    /// <remarks/>
    public void CreateCarAsync(CreateCarServiceRequest request, object userState) {
        if ((this.CreateCarOperationCompleted == null)) {
            this.CreateCarOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateCarOperationCompleted);
        }
        this.InvokeAsync("CreateCar", new object[] {
                    request}, this.CreateCarOperationCompleted, userState);
    }

    private void OnCreateCarOperationCompleted(object arg) {
        if ((this.CreateCarCompleted != null)) {
            System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
            this.CreateCarCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
        }
    }


/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(UserProfileServiceRequest))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RenameGroupServiceRequest))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(CreateCarServiceRequest))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(DeleteGroupServiceRequest))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(GetMgrServiceRequest))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/HF.Rmc.Service.Library.Requests")]
public partial class BaseServiceRequest {

    private string sessionIdField;

    private string userNameField;

    private string viewedUserField;

    private ViewedUserType viewedUserTypeField;

    private bool viewedUserTypeFieldSpecified;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public string SessionId {
        get {
            return this.sessionIdField;
        }
        set {
            this.sessionIdField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public string UserName {
        get {
            return this.userNameField;
        }
        set {
            this.userNameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public string ViewedUser {
        get {
            return this.viewedUserField;
        }
        set {
            this.viewedUserField = value;
        }
    }

    /// <remarks/>
    public ViewedUserType ViewedUserType {
        get {
            return this.viewedUserTypeField;
        }
        set {
            this.viewedUserTypeField = value;
        }
    }

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


public partial class CreateCarServiceRequest : BaseServiceRequest {

    private string accountsField;

    private string carNameField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public string Accounts {
        get {
            return this.accountsField;
        }
        set {
            this.accountsField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public string CarName {
        get {
            return this.carNameField;
        }
        set {
            this.carNameField = value;
        }
    }
} 
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.18408")]
public delegate void CreateCarCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
//
[System.Web.Services.Protocols.SoapDocumentMethodAttribute(“http://relationshipmgmtcenter.hfg.com/services/IRmcService/CreateCar,RequestNamespace=http://relationshipmgmtcenter.hfg.com/services/,ResponseNamespace=http://relationshipmgmtcenter.hfg.com/services/",Use=System.Web.Services.Description.SoapBindingUse.Literal,ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void CreateCar([System.Xml.Serialization.xmlementAttribute(IsNullable=true)]CreateCarServiceRequest请求){
调用(“CreateCar”,新对象[]{
请求});
}
/// 
public void CreateCarAsync(CreateCarServiceRequest请求){
this.CreateCarAsync(请求,空);
}
/// 
public void CreateCarAsync(CreateCarServiceRequest请求,对象用户状态){
如果((this.CreateCarOperationCompleted==null)){
this.CreateCarOperationCompleted=new System.Threading.SendOrPostCallback(this.OnCreateCarOperationCompleted);
}
this.InvokeAsync(“CreateCar”,新对象[]{
请求},this.CreateCarOperationCompleted,userState);
}
CreateCarOperationCompleted上的私有void(对象arg){
如果((this.CreateCarCompleted!=null)){
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs=((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.CreateCarCompleted(this,new System.ComponentModel.AsyncCompletedEventArgs(invokeArgs.Error,invokeArgs.Cancelled,invokeArgs.UserState));
}
}
/// 
[System.Xml.Serialization.XmlIncludeAttribute(typeof(UserProfileServiceRequest))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(RenameGroupServiceRequest))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(CreateCarServiceRequest))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(DeleteGroupServiceRequest))]
[System.Xml.Serialization.xmlcludeAttribute(typeof(GetMgrServiceRequest))]
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.0.30319.34234”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(命名空间=”http://schemas.datacontract.org/2004/07/HF.Rmc.Service.Library.Requests")]
公共部分类BaseServiceRequest{
私有字符串会话字段;
私有字符串userNameField;
私有字符串viewedUserField;
私有ViewedUserType ViewedUserType字段;
指定了专用布尔视图EdUserTypeField;
/// 
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
公共字符串SessionId{
得到{
返回此.sessiondField;
}
设置{
this.sessiondField=值;
}
}
/// 
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
公共字符串用户名{
得到{
返回this.userNameField;
}
设置{
this.userNameField=值;
}
}
/// 
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
公共字符串查看器{
得到{
返回此.viewedUserField;
}
设置{
this.viewedUserField=值;
}
}
/// 
公共视图EdUserType视图EdUserType{
得到{
返回此.viewedUserTypeField;
}
设置{
this.viewedUserTypeField=值;
}
}
/// 
[System.Xml.Serialization.XmlIgnoreAttribute()]
公共bool ViewedUserTypeSpecified{
得到{
返回此.viewedUserTypeFieldSpecified;
}
设置{
this.viewedUserTypeFieldSpecified=值;
}
}
}
公共部分类CreateCarServiceRequest:BaseServiceRequest{
私有字符串accountsField;
私有字符串卡纳梅菲尔德;
/// 
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
公共字符串帐户{
得到{
返回此.accountsField;
}
设置{
this.accountsField=值;
}
}
/// 
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
公共字符串{
得到{
归还这个。卡纳梅菲尔德;
}
设置{
this.carNameField=值;
}
}
} 
/// 
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Web.Services”,“4.0.30319.18408”)]
公共委托void CreateCarCompletedEventHandler(对象发送方,System.ComponentModel.AsyncCompletedEventArgs e);
试试这个:

rmcService.CreateCar(new CreateCarServiceRequest
                    {
                        UserName = userName,
                        ViewedUserType = Enum.Parse(typeof(ViewedUserType), viewedUserType)
                        Accounts = accounts,
                        CarName = carName
                    });  
试试这个:

rmcService.CreateCar(new CreateCarServiceRequest
                    {
                        UserName = userName,
                        ViewedUserType = Enum.Parse(typeof(ViewedUserType), viewedUserType)
                        Accounts = accounts,
                        CarName = carName
                    });  
试试这个:

rmcService.CreateCar(new CreateCarServiceRequest
                    {
                        UserName = userName,
                        ViewedUserType = Enum.Parse(typeof(ViewedUserType), viewedUserType)
                        Accounts = accounts,
                        CarName = carName
                    });  
试试这个:

rmcService.CreateCar(new CreateCarServiceRequest
                    {
                        UserName = userName,
                        ViewedUserType = Enum.Parse(typeof(ViewedUserType), viewedUserType)
                        Accounts = accounts,
                        CarName = carName
                    });  

这是asmx还是svc?乍一看…使用“CreateCarServiceRequest”类的新实例作为参数。。。。但是请想一想:您不能仅更改代理来更改服务器行为。这是svc。我编写的代码基于类似的asmx流程。仅供参考,此客户端是通过“添加Web引用”创建的。它使用传统的ASMX技术,即使服务本身是WCF服务。改为使用“添加服务引用”。您可以发送CSV字符串