Solved

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

Posted on 2009-04-07
9
1,010 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
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…

763 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