PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, May 19, 2022

[FIXED] How to provide complex objects as parameters to web service functions

 May 19, 2022     .net, c#, web-services     No comments   

Issue

I am new to consuming web services with .Net and facing following issue. I have a WSDL with following definition

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

And in code when calling the function

SchoolWebService.RemoteClassApi objSchool = new SchoolWebService.RemoteClassApi();
res= objSchool.ClassTransfer(…)

it required me to provide two parameters: ClassStudent trans & string RollNo

RollNo can be provided simply as a string but I don’t know how to provide trans object?


Solution

Normally the class "ClassStudent" should have been generated so try

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

NB : The class are generated in the folder "services references" of your project. It doesn't follow the "one file one class" principle ;)



Answered By - Pak
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing