Solved

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

Posted on 2009-04-07
9
1,005 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
  • 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now