By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

C# SOAP Authentication to non C# web service

P: n/a
Hi,
I have a gSoap Web Service written using C++, it uses SOAP username and
password authentication.

I also have a C# form client consuming the web service, all this was working
fine until I added the authentication on the server, now I can not get the
client to authenticate. Can someone tell me how to add authentication info
to the SOAP message posted from the C# SOAP client.
here is some code I call to initilize the soap call from the C# form.

public partial class MyForm : Form
{
public MyForm()
{
InitializeComponent();

Service service = new Service();
}
...
...
...
I am using SOAP authentication, with a username and password. Here is the
soap request I would like to receive at the web service. It contains an
Authorization field.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://localhost:80/Service.wsdl"
xmlns:ns2="http://tempuri.org/ns1.xsd"><SOAP-ENV:Body><ns2:getBatteryLevel></ns2:getBatteryLevel></SOAP-ENV:Body></SOAP-ENV:Envelope>POST
/ HTTP/1.1
Host: localhost:8080
User-Agent: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 489
Connection: close
Authorization: Basic dXNlcjpwYXNz
SOAPAction: ""

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://localhost:8080/Service.wsdl"
xmlns:ns2="http://tempuri.org/ns1.xsd"><SOAP-ENV:Body><ns2:GetDBOldestPendingRow><iMaxRows>100</iMaxRows></ns2:GetDBOldestPendingRow></SOAP-ENV:Body></SOAP-ENV:Envelope>
Is there a way I can get this info into the C# client request?

Thanks,
Enda
Jan 15 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Enda,

I believe you posted this before, at least this time you answered the
question of whether or not you are using transport or message security.

Assuming you are using a web reference, you will want to set the
Credentials property on the proxy (in this case, your Service instance, I
believe) to an implementation of the ICredentials class. You would use the
NetwokCrediential instance, setting it to the username/password needed for
the website.

If you were using WCF, you would have to set up the wsHttpBinding to use
transport security, but this would only be allowed if you were using SSL
certificates (https), so that you could guarantee security (WCF won't allow
it otherwise).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Enda Manni" <en*********@hotmail.comwrote in message
news:A7**********************************@microsof t.com...
Hi,
I have a gSoap Web Service written using C++, it uses SOAP username and
password authentication.

I also have a C# form client consuming the web service, all this was
working
fine until I added the authentication on the server, now I can not get the
client to authenticate. Can someone tell me how to add authentication
info
to the SOAP message posted from the C# SOAP client.
here is some code I call to initilize the soap call from the C# form.

public partial class MyForm : Form
{
public MyForm()
{
InitializeComponent();

Service service = new Service();
}
..
..
..
I am using SOAP authentication, with a username and password. Here is
the
soap request I would like to receive at the web service. It contains an
Authorization field.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://localhost:80/Service.wsdl"
xmlns:ns2="http://tempuri.org/ns1.xsd"><SOAP-ENV:Body><ns2:getBatteryLevel></ns2:getBatteryLevel></SOAP-ENV:Body></SOAP-ENV:Envelope>POST
/ HTTP/1.1
Host: localhost:8080
User-Agent: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 489
Connection: close
Authorization: Basic dXNlcjpwYXNz
SOAPAction: ""

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://localhost:8080/Service.wsdl"
xmlns:ns2="http://tempuri.org/ns1.xsd"><SOAP-ENV:Body><ns2:GetDBOldestPendingRow><iMaxRows>100</iMaxRows></ns2:GetDBOldestPendingRow></SOAP-ENV:Body></SOAP-ENV:Envelope>
Is there a way I can get this info into the C# client request?

Thanks,
Enda


Jan 15 '08 #2

P: n/a
Thanks

I added

service.Credentials = new System.Net.NetworkCredential("user", "pass");
but it still does not add the authorization to the SOAP header.
Here is my code:

public MyForm()
{
InitializeComponent();

Service service = new Service();

service.Credentials = new System.Net.NetworkCredential("user",
"pass");
}

I also added a web reference, it was difficult locating it as My web service
is a c++ gSoap web service, I specified the following string to find the web
reference.

http://127.0.0.1:8080/ns1.wsdl
Any more ideas.
Enda

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2****************@TK2MSFTNGP03.phx.gbl...
Enda,

I believe you posted this before, at least this time you answered the
question of whether or not you are using transport or message security.

Assuming you are using a web reference, you will want to set the
Credentials property on the proxy (in this case, your Service instance, I
believe) to an implementation of the ICredentials class. You would use
the NetwokCrediential instance, setting it to the username/password needed
for the website.

If you were using WCF, you would have to set up the wsHttpBinding to
use transport security, but this would only be allowed if you were using
SSL certificates (https), so that you could guarantee security (WCF won't
allow it otherwise).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Enda Manni" <en*********@hotmail.comwrote in message
news:A7**********************************@microsof t.com...
>Hi,
I have a gSoap Web Service written using C++, it uses SOAP username and
password authentication.

I also have a C# form client consuming the web service, all this was
working
fine until I added the authentication on the server, now I can not get
the
client to authenticate. Can someone tell me how to add authentication
info
to the SOAP message posted from the C# SOAP client.
here is some code I call to initilize the soap call from the C# form.

public partial class MyForm : Form
{
public MyForm()
{
InitializeComponent();

Service service = new Service();
}
..
..
..
I am using SOAP authentication, with a username and password. Here is
the
soap request I would like to receive at the web service. It contains an
Authorization field.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://localhost:80/Service.wsdl"
xmlns:ns2="http://tempuri.org/ns1.xsd"><SOAP-ENV:Body><ns2:getBatteryLevel></ns2:getBatteryLevel></SOAP-ENV:Body></SOAP-ENV:Envelope>POST
/ HTTP/1.1
Host: localhost:8080
User-Agent: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 489
Connection: close
Authorization: Basic dXNlcjpwYXNz
SOAPAction: ""

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://localhost:8080/Service.wsdl"
xmlns:ns2="http://tempuri.org/ns1.xsd"><SOAP-ENV:Body><ns2:GetDBOldestPendingRow><iMaxRows>100</iMaxRows></ns2:GetDBOldestPendingRow></SOAP-ENV:Body></SOAP-ENV:Envelope>
Is there a way I can get this info into the C# client request?

Thanks,
Enda


Jan 15 '08 #3

P: n/a
Enda,

It's not supposed to add the authorization to the SOAP header. You
displayed this:

Host: localhost:8080
User-Agent: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 489
Connection: close
Authorization: Basic dXNlcjpwYXNz
SOAPAction: ""

Those are HTTP headers, and the Authorization field in that set of
headers is what is known as transport security. Setting the Credentials
property should set that Authorization field correctly.

If you want to use WS-Security spec, which will allow you to use
authentication/authorization on a ^message^ level, then you won't be able to
use a web reference here. You will have to use the Web Service Enhancements
from MS, or Windows Communications Foundation (WCF).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Enda Manni" <en*********@hotmail.comwrote in message
news:3A**********************************@microsof t.com...
Thanks

I added

service.Credentials = new System.Net.NetworkCredential("user", "pass");
but it still does not add the authorization to the SOAP header.
Here is my code:

public MyForm()
{
InitializeComponent();

Service service = new Service();

service.Credentials = new System.Net.NetworkCredential("user",
"pass");
}

I also added a web reference, it was difficult locating it as My web
service is a c++ gSoap web service, I specified the following string to
find the web reference.

http://127.0.0.1:8080/ns1.wsdl
Any more ideas.
Enda

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:%2****************@TK2MSFTNGP03.phx.gbl...
>Enda,

I believe you posted this before, at least this time you answered the
question of whether or not you are using transport or message security.

Assuming you are using a web reference, you will want to set the
Credentials property on the proxy (in this case, your Service instance, I
believe) to an implementation of the ICredentials class. You would use
the NetwokCrediential instance, setting it to the username/password
needed for the website.

If you were using WCF, you would have to set up the wsHttpBinding to
use transport security, but this would only be allowed if you were using
SSL certificates (https), so that you could guarantee security (WCF won't
allow it otherwise).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Enda Manni" <en*********@hotmail.comwrote in message
news:A7**********************************@microso ft.com...
>>Hi,
I have a gSoap Web Service written using C++, it uses SOAP username and
password authentication.

I also have a C# form client consuming the web service, all this was
working
fine until I added the authentication on the server, now I can not get
the
client to authenticate. Can someone tell me how to add authentication
info
to the SOAP message posted from the C# SOAP client.
here is some code I call to initilize the soap call from the C# form.

public partial class MyForm : Form
{
public MyForm()
{
InitializeComponent();

Service service = new Service();
}
..
..
..
I am using SOAP authentication, with a username and password. Here is
the
soap request I would like to receive at the web service. It contains an
Authorization field.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://localhost:80/Service.wsdl"
xmlns:ns2="http://tempuri.org/ns1.xsd"><SOAP-ENV:Body><ns2:getBatteryLevel></ns2:getBatteryLevel></SOAP-ENV:Body></SOAP-ENV:Envelope>POST
/ HTTP/1.1
Host: localhost:8080
User-Agent: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 489
Connection: close
Authorization: Basic dXNlcjpwYXNz
SOAPAction: ""

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://localhost:8080/Service.wsdl"
xmlns:ns2="http://tempuri.org/ns1.xsd"><SOAP-ENV:Body><ns2:GetDBOldestPendingRow><iMaxRows>100</iMaxRows></ns2:GetDBOldestPendingRow></SOAP-ENV:Body></SOAP-ENV:Envelope>
Is there a way I can get this info into the C# client request?

Thanks,
Enda



Jan 15 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.