473,327 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Inserting items into the SOAP Header from C# Client to call a webservice

I'm trying to call a Webservice (Non-.NET) That requires the insertion
of security credentials into the SOAP header. Up until know I've been
creating Dynamic proxy classes to call web services and not been
dealing with the inner workings of SOAP.

Looks Like I need to learn a little about soap and Manually calling
Web Services.....

Any help will be very appreciated !!!

I've been told my SOAP message needs to look as follows:

<SOAP-ENV:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/
secext">
<wsse:UsernameToken>
<wsse:Username>AUSER</wsse:Username>
<wsse:Password Type="wsse:PasswordText">APassword</
wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:Search_spcUser xmlns:ns1="http://myapp.com/asi">
<UserId>John</UserId>
</ns1:Search_spcUser>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Feb 26 '07 #1
6 46728

Well, if it were a c# webservice, it would have a class such as:

public class AuthHeader : SoapHeader
{
public string Username;
public string Password;
}

And the method would have the [SoapHeader ("Authentication")] attribute.
From your client you would consume the webservice like:

private Wsvs.AuthHeader Authorization = new Wsvs.AuthHeader();

and

//SOAP Authorization request
Authorization.Username="test";
Authorization.Password="test";
reg.AuthHeaderValue=Authorization;
Can you not do something like this with the Non-.NET webservice?
John wrote:
I'm trying to call a Webservice (Non-.NET) That requires the insertion
of security credentials into the SOAP header. Up until know I've been
creating Dynamic proxy classes to call web services and not been
dealing with the inner workings of SOAP.

Looks Like I need to learn a little about soap and Manually calling
Web Services.....

Any help will be very appreciated !!!

I've been told my SOAP message needs to look as follows:

<SOAP-ENV:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/
secext">
<wsse:UsernameToken>
<wsse:Username>AUSER</wsse:Username>
<wsse:Password Type="wsse:PasswordText">APassword</
wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:Search_spcUser xmlns:ns1="http://myapp.com/asi">
<UserId>John</UserId>
</ns1:Search_spcUser>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Feb 26 '07 #2
Unfortunately I have no control over the "Non-.NET webservice" so I
have to figure out a way to manually insert into the SOAP Header. I've
never Manually created a SOAP request and passed it to a Web
Service. I'm hoping it is *fairly* straightforward.
Feb 26 '07 #3
Hi,

Try this please:
static void Main( string[] args )
{
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequest.C reate(
"http://url_of_your_web_service" );
string strSOAPRequestBody = "<SOAP-ENV:Header>" +
"<wsse:Security
xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/07/secext\">" +
"<wsse:UsernameToken>" +
"<wsse:Username>AUSER</wsse:Username>" +
"<wsse:Password
Type=\"wsse:PasswordText\">APassword</wsse:Password>" +
"</wsse:UsernameToken>" +
"</wsse:Security>" +
"</SOAP-ENV:Header>" +
"<SOAP-ENV:Body>" +
"<ns1:Search_spcUser xmlns:ns1=\"http://myapp.com/asi\">" +
"<UserId>John</UserId>" +
"</ns1:Search_spcUser>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>";
request.Method = "POST";
request.ContentType = "application/soap+xml; charset=utf-8";
request.ContentLength = strSOAPRequestBody.Length;
System.IO.StreamWriter streamWriter =
new System.IO.StreamWriter( request.GetRequestStream() );
streamWriter.Write( strSOAPRequestBody );
streamWriter.Close();
System.IO.StreamReader streamReader =
new System.IO.StreamReader(
request.GetResponse().GetResponseStream() );
string strResponse = "";
while( !streamReader.EndOfStream )
strResponse += streamReader.ReadLine();
reader.Close();
}
At the end, strResponse will contain the XML of whatever the service has
returned to you. Of course you will need to parse that XML into a
XmlDocument and use that document to read whatever data is there.
"John" <19*****@gmail.comwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
Unfortunately I have no control over the "Non-.NET webservice" so I
have to figure out a way to manually insert into the SOAP Header. I've
never Manually created a SOAP request and passed it to a Web
Service. I'm hoping it is *fairly* straightforward.


Feb 26 '07 #4
John wrote:
Unfortunately I have no control over the "Non-.NET webservice" so I
have to figure out a way to manually insert into the SOAP Header. I've
never Manually created a SOAP request and passed it to a Web
Service. I'm hoping it is *fairly* straightforward.

I've done such in Java.

I open a socket and send the raw SOAP/XML header and data to consume the
web service.

It wasn't a big deal, but I wasn't using an authorized web service
either. There's just a lot of string manipulation and parsing involved.
So it looks like:

// send an HTTP request to the web service
out.println("POST " + WebServicePath + " HTTP/1.1");
out.println("Host: " + Server);
out.println("Content-Type: text/xml; charset=utf-8");
out.println("Content-Length: " + String.valueOf(length));
//out.println("Content-Length: " + "398");
out.println("SOAPAction: \"" + SoapAction + "\"");
out.println("Connection: Close");
out.println();

out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
out.println("<soap:Envelope
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
out.println("<soap:Body>");
out.println("<" + MethodName + " xmlns=\"" + XmlNamespace + "\">");

//Parameters passed to the method are added here
for (int t = 0; t < namevec.size(); t++) {
String name = (String) namevec.elementAt(t);
String data = (String) datavec.elementAt(t);
out.println("<" + name + ">" + data + "</" + name + ">");

}

out.println("</" + MethodName + ">");
out.println("</soap:Body>");
out.println("</soap:Envelope>");
out.println();
Feb 27 '07 #5
John wrote:
Unfortunately I have no control over the "Non-.NET webservice" so I
have to figure out a way to manually insert into the SOAP Header. I've
never Manually created a SOAP request and passed it to a Web
Service. I'm hoping it is *fairly* straightforward.


BTW,

You should still be able to add a WebReference to your client project
and see what's available as far as methods on the Non-.NET webservice by
using the object browser.

Feb 27 '07 #6

I had the same issue and Ashot's code worked perfectly for me! Thank
you for the great example!

Dimitar

On Feb 26, 6:06 pm, "Ashot Geodakov" <a_geoda...@hotmail.comwrote:
Hi,

Try this please:

static void Main( string[] args )
{
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequest.C reate(
"http://url_of_your_web_service" );
string strSOAPRequestBody = "<SOAP-ENV:Header>" +
"<wsse:Security
xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/07/secext\">" +
"<wsse:UsernameToken>" +
"<wsse:Username>AUSER</wsse:Username>" +
"<wsse:Password
Type=\"wsse:PasswordText\">APassword</wsse:Password>" +
"</wsse:UsernameToken>" +
"</wsse:Security>" +
"</SOAP-ENV:Header>" +
"<SOAP-ENV:Body>" +
"<ns1:Search_spcUser xmlns:ns1=\"http://myapp.com/asi\">" +
"<UserId>John</UserId>" +
"</ns1:Search_spcUser>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>";
request.Method = "POST";
request.ContentType = "application/soap+xml; charset=utf-8";
request.ContentLength = strSOAPRequestBody.Length;
System.IO.StreamWriter streamWriter =
new System.IO.StreamWriter( request.GetRequestStream() );
streamWriter.Write( strSOAPRequestBody );
streamWriter.Close();
System.IO.StreamReader streamReader =
new System.IO.StreamReader(
request.GetResponse().GetResponseStream() );
string strResponse = "";
while( !streamReader.EndOfStream )
strResponse += streamReader.ReadLine();
reader.Close();
}

At the end, strResponse will contain the XML of whatever theservicehas
returned to you. Of course you will need to parse that XML into a
XmlDocument and use that document to read whatever data is there.

"John" <1944...@gmail.comwrote in message

news:11**********************@k78g2000cwa.googlegr oups.com...
Unfortunately I have no control over the "Non-.NETwebservice" so I
have to figure out a way to manually insert into theSOAPHeader. I've
never Manually created aSOAPrequest and passed it to aWeb
Service. I'm hoping it is *fairly* straightforward.- Hide quoted text -

- Show quoted text -

Apr 20 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Q. John Chen | last post by:
All, I have a WebService created in .NET. I have VB6 Client consume the WebService (using Soap ToolKit 3.0) But I have couple user who got error accessing the WebServer with error message...
5
by: jb | last post by:
*Please* help --- I'm tearing my hair out. I want to use sessionstate in a webservice, accessed from a client, written in script (JScript, InfoPath). I have written my webservice (C# .NET). I...
6
by: john deviney | last post by:
I have a C#/.Net 1.1 client talking to a Java based web service. I need to insert a soap header on the client side which is expected on the server side. Currently, the Java ws provider, Axis, does...
0
by: Daniel Thune, MCSE | last post by:
I am having a problem with formatting a SOAP Header in a .Net client. The client calls a Java Axis 1.1 based web service. In order to authenticate the caller, the web service call is intercepted by...
6
by: A.M-SG | last post by:
Hi, We are developing a SmartClient application and we are planning to expose business objects layer to SmartClient application by using ASP.NET SOAP web services.
3
by: Sydney | last post by:
Hi, I am trying to construct a WSE 2.0 security SOAP request in VBScript on an HTML page to send off to a webservice. I think I've almost got it but I'm having an issue generating the nonce...
0
by: Samuel Zallocco | last post by:
Hi all, I've a problem with PHP5 + PEAR::SOAP. I Have the following 2 script that implements a simple web service: The Server Code running on WinXP + PHP5 + Apache 2.x:...
6
by: Peter van der veen | last post by:
Hi I have the following problem. I'm calling a webservice from within a VB.net 2005 Windows program. For this i got a WSDL file and loaded that in VB. Until now i just call the webservice and...
1
by: novicedlh | last post by:
Hello, I am creating a webservice that collects user information and stores it in a database. Since the user information contains sensitive data like SSN I am planning to use WS-Security (WSE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.