[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2009-04-07
9
Medium Priority
?
1,021 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

649 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