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
Solved

soap response help c#

Posted on 2007-11-21
13
616 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
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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