Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将复杂对象作为参数提供给web服务功能_C#_.net_Web Services - Fatal编程技术网

C# 如何将复杂对象作为参数提供给web服务功能

C# 如何将复杂对象作为参数提供给web服务功能,c#,.net,web-services,C#,.net,Web Services,我不熟悉使用.Net使用web服务,并且面临以下问题。我有如下定义的wsdl <s:element name="ClassTransfer"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="trans" type="tns:ClassStudent" /> <

我不熟悉使用.Net使用web服务,并且面临以下问题。我有如下定义的
wsdl

<s:element name="ClassTransfer">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="trans" type="tns:ClassStudent" />
            <s:element minOccurs="0" maxOccurs="1" name="RollNo" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ClassStudent">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="Subject" type="s:string" />
…
        </s:sequence>
      </s:complexType>
它要求我提供两个参数:
ClassStudent trans&string RollNo

RollNo
可以简单地作为字符串提供,但我不知道如何提供
trans
对象

请帮助。

通常应该生成“ClassStudent”类,因此请尝试

var studentToTransfer = new ClassStudent {Subject = "Foo"};
SchoolWebService.RemoteClassApi objSchool = new SchoolWebService.RemoteClassApi();
res= objSchool.ClassTransfer(studentToTransfer , "5A" );

注意:该类是在项目的“服务引用”文件夹中生成的。它不遵循“一个文件一个类”的原则;)

将生成
ClassStudent
类型。检查IntelliSense弹出窗口或对象浏览器中的方法
ClassTransfer
,您将看到它所需的类型。
var studentToTransfer = new ClassStudent {Subject = "Foo"};
SchoolWebService.RemoteClassApi objSchool = new SchoolWebService.RemoteClassApi();
res= objSchool.ClassTransfer(studentToTransfer , "5A" );