soap response help c#

Posted on 2007-11-21
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="" xsi:type="ns3:ComplexType" xmlns:soapenc="" xmlns:ns3="http://......">
  <id href="#id1"/>
  <display xsi:type="soapenc:string">display value</display>
  <name xsi:type="soapenc:string">name value</name>  

<multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="" xsi:type="soapenc:long" xmlns:soapenc="">123</multiRef>
Question by:dalecon
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
LVL 40

Expert Comment

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.
LVL 40

Expert Comment

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!

Author Comment

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
Technology Partners: 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

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

Author Comment

ID: 20328948


Expert Comment

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.

Author Comment

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#

Expert Comment

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.

Author Comment

ID: 20338299

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


Author Comment

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();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();

Accepted Solution

photowhiz earned 50 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

There is an example of a SOAP request at 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, 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.

Expert Comment

ID: 20521762
Forced accept.

EE Admin

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a WebAPI using a generic return parameter 9 41
.NET Enums [Flags] & Bitwise Design Question 6 39
Need help with another query 10 38
C# LINQ 5 25
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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…

749 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