Solved

soap response help c#

Posted on 2007-11-21
13
595 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
  • 6
  • 3
  • 2
  • +1
13 Comments
 
LVL 40

Expert Comment

by:evilrix
Comment Utility
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
Comment Utility
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
Comment Utility

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
 

Author Comment

by:dalecon
Comment Utility

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
Comment Utility


Anyone?
0
 
LVL 7

Expert Comment

by:photowhiz
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:dalecon
Comment Utility

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
Comment Utility
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
Comment Utility

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

0
 

Author Comment

by:dalecon
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
Forced accept.

Computer101
EE Admin
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

10 Experts available now in Live!

Get 1:1 Help Now