[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-04-07
9
Medium Priority
?
1,025 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
Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

 

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

Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

872 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