Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

soap response help c#

Posted on 2007-11-21
13
Medium Priority
?
662 Views
Last Modified: 2010-04-15
hi all
i'm calling a webservice using c# in a windows app that returns a complex type []

ComplextType [] complextType = null;
complextType = service.getMethod(a, b, c, d)
then iterating through to ge the results, here i'm using c# (visual studio 2005) inttli sense
for (int i = 0; i < complextType .Length; i++)
{
  string name = complextType [i].name;
  string display = complextType [i].name;
}
and this bring back the results.  BUT i want to retrun the id, but this keeps coming back as null
I've done a tcptrace on the raw soap response and i can see the id has a value, however when i do complextType [i].id the value is null

looking at the siap response i can see the id value (123) but it's in a separate multifred tag, is anone able to show me how i get the id?

soap :

<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:ComplexType" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns3="http://......">
  <id href="#id1"/>
  <display xsi:type="soapenc:string">display value</display>
  <name xsi:type="soapenc:string">name value</name>  
</multiRef>

<multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:long" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">123</multiRef>
0
Comment
Question by:dalecon
[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
  • 6
  • 3
  • 2
  • +1
13 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 20327397
Looking at the soap response I don't think the id in it and the id you are expecting are the same thing. If you look at the response for name and display you can see they are defined as types, id isn't -- it's a href. Can you change the name of what's being returned (is this your web service?)? If so, try changing it from id to myid just to see if the soap response changes. I suspect it won't, indicating id isn't actually being returned.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20327414
Ah, forget all that -- I've just spotted the definition of id1 underneath -- I didn't have my browser scrolled up enough - doh! Ok, so it looks like it is returned as a long. I'm wondering why it is returned as a reference to a type rather than inline as name and display are!
0
 

Author Comment

by:dalecon
ID: 20327667

have no idea why it's been done like that.  Itt's not my webservice so i can't chnage it unfortuantely, but i need  to grab the id and so i can use it elsewhere
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dalecon
ID: 20327907

is anyone able to tell me how i get the soap response using c#

so instead of complextType = service.getMethod(a, b, c, d)
i can do rawsoap = service.getMethod(a, b, c, d)
then i can try and parse the xml document that is retruned
0
 

Author Comment

by:dalecon
ID: 20328948


Anyone?
0
 
LVL 7

Expert Comment

by:photowhiz
ID: 20335721
While it is possible to parse the SOAP message and pull out individual values, this is very difficult and will break when the server changes the message. The standard way to do this is for the server to supply a WSDL file or service that describes the message. Dot Net has functions to retrieve class instances from WSDLs. Get whoever supplies the web service to supply a WSDL.
0
 

Author Comment

by:dalecon
ID: 20336177

i've got the wsdl and added this as a web reference to my windows project
the problem i've got is when i iterate through the method results like this

for (int i = 0; i < complextType .Length; i++)
{
  string id = complextType [i].ID;
  string name = complextType [i].name;
  string display = complextType [i].display;
}

The ID field is null, this is becasue the id field is referenced rather than inline with the name and display fields.  I don't know how to get the values for the the ID that is referenced

The only way i can think of it to grab the soap response (which is the xml i posed above taken from tcp trace) and parse it

But i can't get the soap response using c#
0
 
LVL 7

Expert Comment

by:photowhiz
ID: 20337067
Try to get the server to include the multiRef in the the complexType, or return the ID as a value as well as an attribute.

If they won't do that you can call the service directly with System.Net.WebRequest.Create and parse the reply as XML. That will be a lot of work.
0
 

Author Comment

by:dalecon
ID: 20338299

are you able to help me with System.Net.WebRequest.Create ?

0
 

Author Comment

by:dalecon
ID: 20338330
Using the code below shows me the WSDL file (i can already see this if i put the wsdl endpoint in my broswer), it doen't show me the response of the actual method i'm calling which is what i want


System.Net.WebRequest request = System.Net.WebRequest.Create (Endpoint);
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
MessageBox.Show(response.StatusDescription);
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
MessageBox.Show(responseFromServer);                
reader.Close();                
dataStream.Close();              
 response.Close();
0
 
LVL 7

Accepted Solution

by:
photowhiz earned 200 total points
ID: 20340132
You are not constructing a SOAP request, you are simply issuing a request to the server. The difference is a great as that between knowing the phone number of a lawyer (getting a WSDL) and being a lawyer (parsing the SOAP data described by the WSDL).

You have to construct a SOAP request envelope according to the server schema, issue the request with the authentication described by the schema, parse the response returned by the server, and act according to the schema. I don't think you realize the difficulty of what you are attempting.

If you are determined to issue and parse SOAP transactions programmatically, start by familiarizing yourself with SOAP, the .Net System.Net.HttpWebRequest class, and the server's WSDL. You can find an introduction to SOAP at http://www.soapuser.com/index.html.

There is an example of a SOAP request at http://www.eggheadcafe.com/articles/20011103.asp. The request is hard-coded to a predefined server, it won't work on any other server, but you will get an idea how to construct a request.

Microsoft has a COM interface to a free SOAP client described at http://msdn2.microsoft.com/en-us/library/ms997641.aspx#xpsoap_simple, it may help you.

You are looking at days of work and hundreds of lines of code to do this, and redoing it again when the server changes their message. You will better spend your time trying to get the owners of the server to supply the data you want in their web methods.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20521762
Forced accept.

Computer101
EE Admin
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

618 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