我如何将userContext对象传递给Web服务

问题描述 投票:0回答:1

我是Web服务和Visual Studio的新手

我正在尝试创建一个客户端以连接到财务Web服务和GetCurrentPeriod。

我正在Visual Studio 2017中进行测试,我已经通过使用添加服务引用输入WSDL来连接到Web服务。我创建了一个带有按钮和标签的基本表单,以显示结果。

这是我的距离,但是GetCurrentPeriod()调用需要连接参数。

错误消息是

CS7036-没有提供与'DocumentServiceClient.GetCurrentPeriod(UserContextWebObject,string)'的所需形式参数'userContext'相对应的参数]

WSDL说我需要通过这个。

<xs:complexType name="UserContextWebObject">
<xs:sequence>
<xs:element name="Username" type="xs:string" maxOccurs="1" minOccurs="0"/>
<xs:element name="Password" type="xs:string" maxOccurs="1" minOccurs="0"/>
<xs:element name="Database" type="xs:string" maxOccurs="1" minOccurs="0"/>
<xs:element name="Server" type="xs:string" maxOccurs="1" minOccurs="0"/>
<xs:element name="DatabaseType" type="tns:DatabaseTypeWebObject" maxOccurs="1" minOccurs="1"/>
<xs:element name="Company" type="xs:string" maxOccurs="1" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

如何将复杂对象作为参数传递?

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DocumentWebServices
{
    public partial class CallGetCurrentPeriod : System.Web.UI.Page

    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnGetCurrentPeriod_Click(object sender, EventArgs e)
        {
            DocumentService.DocumentServiceClient client = new DocumentService.DocumentServiceClient();
            client.GetCurrentPeriod(

                );    

        }
    }
}
c# visual-studio webservice-client
1个回答
0
投票

您是如何生成代理类的?通过URL还是通过WSDL文件?如果是通过WSDL文件生成的,则好像缺少一个XSD文件,该文件定义了DatabaseTypeWebObject的架构。您将需要为该对象的定义生成另一个代理类,以便可以将其传递到操作GetCurrentPeriod中。希望对您有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.