C#/Webservice/Results to proper SOAP format

Batista

Executive Member
Joined
Sep 2, 2011
Messages
7,906
Reaction score
266
Hi guys

A quick one here.Im not so familiar in webservices but i have written one and its working correctly and its returning the data like so in an XML format (Note - I have removed closing tags for readability):

-The elements in the datatable (columns) - followed by the recordset.

Code:
<DataTable> 
<xs:schema id="NewDataSet"><xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Results" msdata:UseCurrentLocale="true"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="Results"><xs:complexType><xs:sequence><xs:element name="STATUS" type="xs:string" minOccurs="0"/>
</xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><diffgr:diffgram><DocumentElement><Results diffgr:id="Results1" msdata:rowOrder="0"><STATUS>Active</STATUS>
</DataTable>


I need to get it into this format- from http://www.w3schools.com/webservices/ws_soap_example.asp
Code:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
[B]MY RESULTS GO HERE NOW!![/B]
</soap:Body>

</soap:Envelope>



How do i do this?Surely its not a manual thing?

Thanks ;)
 
Hi. How do you know what it is returning? If you use a testing tool like SoapUI and call your service, you will notice that the headers and soap envelope are probably all there. But if you are using a .Net client, it has already stripped out the envelope.
 
Hi. How do you know what it is returning? If you use a testing tool like SoapUI and call your service, you will notice that the headers and soap envelope are probably all there. But if you are using a .Net client, it has already stripped out the envelope.

Hey Dude

Im just testing it via Internet explorer? Ahh i see what you mean.IE prob strips its out also?
 
Yes I think that you are using IE to browse to the incestuous test form which is hosted with .Net web services. It's a confusing concept.

Btw depending on your use, accepting/returning string values containing XML (especially a serialized DataSet) may be a worse choice than simply defining a class for your parameter/return value. Just mentioning because I was guilty of this myself.
 
Yes I think that you are using IE to browse to the incestuous test form which is hosted with .Net web services. It's a confusing concept.

Btw depending on your use, accepting/returning string values containing XML (especially a serialized DataSet) may be a worse choice than simply defining a class for your parameter/return value. Just mentioning because I was guilty of this myself.

Its cool, the external company wants the results in an XML Soap format.Installing SOAPUI now...
 
Hey Gob

Im getting the following error when trying to load it in SOAPUI

Error loading [http://localhost:50954/Service1.svc?wsdl]: org.apache.xmlbeans.XmlException: java.io.FileNotFoundException: http://localhost:50954/Service1.svc?wsdl

I access the webservice with this : http://localhost:50954/Service1.asmx
Pls help? :D

Hey Dude

I came right now, I just added the webservice to my visual studio project and then it generated the WSDL and i was able to pick it up in SOAPUI! I just need to learn what im doing in SOAP UI now.
 
Its a webservice lol and like i said i havnt worked on webservices in a while...I will install SOAPUI and report back :) thanks!

yes obviously, but it is invalid to send a non-SOAP request, and get a SOAP response, therefore pasting a URL into a browser violates the SOAP protocol :)

Your request must include an envelope with a payload and a SOAP action header.


SOAP-UI is lank useful. not only can it generate and run tests against your service, it can also create a stub of the service running on a random localhost port, so you dont have to send actual requests to the service to test your integration
 
Last edited:
Hey Guys

Thanks for the replies thus far.I think im almost there now, just wondering why this basic webservice wont display the intended results?Its supposed to show the results of the addition in the right window...

Soap.jpg

Why da *** is this picture so small


Left window
Code:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:Add>
         <tem:x>1</tem:x>
         <tem:y>3</tem:y>
      </tem:Add>
   </soapenv:Body>
</soapenv:Envelope>

Right window :
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
      <title>IIS7</title>
      <style type="text/css">
         <!--body {
	color:#000000;
	background-color:#B3B3B3;
	margin:0;
}

#container {
	margin-left:auto;
	margin-right:auto;
	text-align:center;
	}

a img {
	border:none;
}-->
      </style>
   </head>
   <body>
      <div id="container">
         <a href="http://go.microsoft.com/fwlink/?linkid=66138&amp;clcid=0x409">
            <img src="welcome.png" alt="IIS7" width="571" height="411"/>
         </a>
      </div>
   </body>
</html>
 
Last edited:
Hi Batista.. I am not sure what the issue is... it looks like SoapUI is returning the IIS home page.

Your SoapUI test should be calling the web service at http://localhost/WebService/Service1.asmx
So first paste that Url into a browser to check that your web service is available at that Url (it will display your service methods)
If not, then your web service is not properly set up in IIS... the virtual directory "WebService" on the IIS default site should be pointing to a folder where your service is published.
 
Hi Batista.. I am not sure what the issue is... it looks like SoapUI is returning the IIS home page.

Your SoapUI test should be calling the web service at http://localhost/WebService/Service1.asmx
So first paste that Url into a browser to check that your web service is available at that Url (it will display your service methods)
If not, then your web service is not properly set up in IIS... the virtual directory "WebService" on the IIS default site should be pointing to a folder where your service is published.


Thanks man, I can confirm that my webservice is working when tested on a browser.Im using Visual studio to do the webservice in and i noticed that when i run it from there it adds a port to the end of localhost like so :

http://localhost:60936/WebServices/Service1.asmx
 
In your SoapUI request, click on the Url and select "edit endpoint" and change it to http://localhost:60936/WebServices/Service1.asmx

(That is to test from SoapUI to the service that you are running from Visual studio)

Rather test that from SoapUI first, then worry about getting it running on IIS if needed.


Cool thanks, I think im confusing myself here because im trying to configure it in IIS and then test it in SOAP - Will follow your advice and leave IIS out of the equation and start from scratch and then just use SOAP on the one running on Visual studio 2010.

Is there a way to configure SOAPUI to use my username and password for each request because i have to type it in individually otherwise i get authentication issues?
 
Last edited:
Im getting somewhere now, but not where i need to be :( This is what I get in the response window now :
Code:
<html><head><title>10.xx.xx.xxx - /</title></head><body><H1>10.xx.xx.xxx - /</H1><hr>

<pre> 3/18/2014 10:23 AM        &lt;dir&gt; <A HREF="/custerr/">custerr</A><br>  4/9/2014  3:00 PM        &lt;dir&gt; <A HREF="/history/">history</A><br> 3/18/2014 10:45 AM        &lt;dir&gt; <A HREF="/logs/">logs</A><br> 3/18/2014 10:24 AM        &lt;dir&gt; <A HREF="/temp/">temp</A><br>  4/9/2014  2:31 PM          168 <A HREF="/web.config">web.config</A><br>  4/9/2014  9:46 AM        &lt;dir&gt; <A HREF="/wwwroot/">wwwroot</A><br></pre><hr></body></html>
dafaq :wtf:
 
Top
Sign up to the MyBroadband newsletter
X