?
Solved

How do I return multiple values from a web service method?

Posted on 2009-04-07
9
Medium Priority
?
1,014 Views
Last Modified: 2013-11-07
Hi,
My web service has a method
public string Activate(string accountXML)
and my XML schema for web service request and XML schema for Return data are as shown in the "Code" section. And I need to strictly follow the above method signature.
Could you please tell me if it is possible to accept a string of values and return a string of values? Thanks for any help or suggestions!
//XML schema for web service request
  <?xml...>
<xs:schema id="acct" ....>
<xs:element name="AccountRequest" msdata:IsDataSet="true">
	<xs:complexType>
   		<xs:choice maxOccurs="Unbounded">
			<xs:element name="Activate">
			 <xs:complexType>
			   <xs:sequence>
			    <xs:element name="FirstName" type="xs:string" minOccurs="0"/>
			    <xs:element name="LastName" type="xs:string" minOccurs="0"/>
			    <xs:element name="Email" type="xs:string" minOccurs="0"/>
			    <xs:element name="Group" type="xs:string" minOccurs="0"/>
			   </xs:sequence>
			 </xs:complexType>
			</xs:element>
		</xs:choice>
	</xs:complexType>
</xs:element>
</xs:schema>
 
//XML schema for Return data
<?xml...>
<xs:schema id="acctReturn" ....>
<xs:element name="acctReturn" msdata:IsDataSet="true">
	<xs:complexType>
   		<xs:choice maxOccurs="Unbounded">
			<xs:element name="Transaction">
			 <xs:complexType>
			   <xs:sequence>
			    <xs:element name="Success" type="xs:boolean" minOccurs="0"/>
			    <xs:element name="Desc" type="xs:string" minOccurs="0"/>
			    <xs:element name="Value" type="xs:string" minOccurs="0"/>
			    <xs:element name="Date" type="xs:date" minOccurs="0"/>
			   </xs:sequence>
			 </xs:complexType>
			</xs:element>
		</xs:choice>
	</xs:complexType>
</xs:element>
</xs:schema>

Open in new window

0
Comment
Question by:ipjyo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24099777
That should be possible...what kind of "string values" are you talking about?
0
 

Author Comment

by:ipjyo
ID: 24100670
hi, thanks for the response.

I need to pass some values as
Group = "123"
firstname = "john"
lastname = "Mike"
email = "john@yahoo.com"
IsAdmin = "true"
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24101377
I would define a class that has those properties in the web service, and pass that object back to the caller.  SOAP will encapsulate that class, to that the client can use the type after updating the web reference.
0
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 

Author Comment

by:ipjyo
ID: 24101479
So do you mean my web method should look like

public  AcctActivate(string GroupNumber, string FirstName, string LastName, string EmailAddress)

Thank you
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24101502
I thought you said something about returning multiple values?  Are you saying that you want to pass multiple values into the web method or get them back (or both)?
0
 

Author Comment

by:ipjyo
ID: 24101843
I am sorry if I forgot to mention it in the question tag? But could you please have a look at my method signature in my initial post? It also included XML schemas. What I am confused about is that these XML schemas are having multiple elements under a <xs:complexType> but the method signature is as follows. How is it possible to pass all the values in place of "accountXML" object in the method signature below? Thank you!
public string Activate(string accountXML)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24102056
Are you saying that you need to pass in a XML string as an argument that conforms to the XSD that you have shown?  If that is true, then you could create that with either an XmlTextWriter or an XmlDocument.
0
 

Author Comment

by:ipjyo
ID: 24102353
yes, I need to pass in an XML string to conform to the XSD.
ok, Thats what I wanted to clarify. Can I just load the XML string into an XMLDocument and parse it for the values? It would be great if you already have such a code with you so it would be helpful for me. I am completely new to these web services and passing XML as parameter. Thanks for all the help you provided!
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 24102547
If you have the XSD, then you can use this tool to generate a class that you can serialize with an XmlSerializer:

Sample Code Generator 1.4.2.1
http://www.microsoft.com/downloads/details.aspx?FamilyID=89E6B1E5-F66C-4A4D-933B-46222BB01EB0&displaylang=en
0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question