Link to home
Start Free TrialLog in
Avatar of dalecon
dalecon

asked on

soap response help c#

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>
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
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!
Avatar of dalecon
dalecon

ASKER


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
Avatar of dalecon

ASKER


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
Avatar of dalecon

ASKER



Anyone?
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.
Avatar of dalecon

ASKER


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#
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.
Avatar of dalecon

ASKER


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

Avatar of dalecon

ASKER

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();
ASKER CERTIFIED SOLUTION
Avatar of photowhiz
photowhiz
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin