473,404 Members | 2,195 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,404 software developers and data experts.

System.Web.Services Authentication?

Hi,

I am trying to put together a small app that uses one of my company's
web service. Originally I interfaced with this web service using java,
and have the example code. I believe the web service was written with
java. Since this web services uses soap I should have no problems
consuming it from other languages, although I'm having a problem
with .net.

The web service requires authentication. I tried adding the
authentication, but still kept getting an exception with the exception
saying something about "could not process the body of the message". So
I decided to use TcpTrace to figure out what was really going on.

I compared what should be 2 identical calls to the web service, one
from .net, one from java. The only pertinent difference I see is the
parameter "Authorization". The java web service call contains this,
and the .net one does not.

Based on the response message from the server I did some searching and
found that someone else had run into a similar problem and their
solution was to add the authentication information manually to the
request header, but did not leave a description on how to do that.

Is it possible to manually add the authentication information to the
request? Is there something I'm missing to force .net to authenticate?
Why don't the credentials I added to the web service work? Or is it
something else entirely?

Below is the code I used to make the web service call, the request,
the request made from a good java call, and the response from the
server with the .net call.

Thanks for your help,
Will

This is the code I use for .net (in VB):
webservice = New MyCompanysWebService()
Dim creds As System.Net.NetworkCredential = New
System.Net.NetworkCredential()
creds.UserName = "username"
creds.Password = "password"
webservice.Credentials = creds
webservice.PreAuthenticate = True
webserice.MyMethodCall(arguments)

This is the resulting call to the web server:
POST /soap/rpc HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client
Protocol 2.0.50727.42)
VsDebuggerCausalityData: uIDPoyeSbaxKao9EtV5QrGihJU0AAAAALItHCIPp
+E68IP7kjv5l3vhSsn2pM0RKn8cJ9xcdWeEACAAA
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Host: localhost:6666
Content-Length: 2598
Expect: 100-continue
Connection: Keep-Alive

<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
.....
This is the call that is made from java:
POST /soap/rpc HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related,
text/*
User-Agent: Axis/1.4
Host: localhost:6666
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 3592
Authorization: Basic
dml0YWxfd2luZG93c19hZF9hcHA6a1FPY2tjR3g4eFhjY2lGT3 Y=

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
....
This is the response I get from the .net call:
HTTP/1.0 500 Internal Server Error
Set-Cookie: ssnid=6896yS4Rvrn2IbkQuOnVJ40m|gwmhc-6666173; path=/;
Content-Type: text/xml;charset=utf-8
Connection: Keep-Alive
Content-Length: 844

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>[ISS.0088.9134] Exception occurred while processing
the body of the message</faultstring>
<faultactor>http://localhost:6666/soap/rpc</faultactor>
<detail xmlns:webM="http://www.webMethods.com/2001/10/soap/
encoding">
<webM:exception>
<webM:className>com.wm.app.b2b.server.AccessExcept ion</
webM:className>
<webM:message xml:lang="">[ISS.0084.9004] Access Denied</
webM:message>
</webM:exception>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Mar 28 '07 #1
1 8655
For anyone else who may encounter this issue, or for the curious,
after hours of searching I finally found a definite answer and
example. The link is here: http://mark.michaelis.net/Blog/Calli...ntication.aspx

Basically it's a problem with using .net and a server that's using
webmethods. .net doesn't negotiate the authentication the way web
methods expects it. Check out the link for more detail. The below code
is a partial class which only needs to be included in your project and
you can regenerate your webservice proxy all you want because the
generated code comes out as a partial class. The only requirements are
that you have the Namespace set correctly, along with the class name.

I actually found a small bug in the code provided on the site, and it
was the "Basic " string in the call to GetBytes. If you don't include
the space the converted username/password will be smushed against it
and you will get an error from the server. The server expects
something like:
Authorization: Basic abcdefencodedusernameandpasswordxyz
without the space you get
Authorization: Basicabcdefencodedusernameandpasswordxyz
and an error from the server about a bad string length.

Thanks to anyone who may have been looking into my problem,
Will

I re-wrote the code in VB to fit along with my project, here is the
code:
Namespace MyWebServiceNameSpace
Partial Public Class MyWebServiceClass
Inherits System.Web.Services.Protocols.SoapHttpClientProtoc ol

Protected Overrides Function GetWebRequest(ByVal myUri As Uri)
As System.Net.WebRequest
Dim request As System.Net.HttpWebRequest
request = CType(MyBase.GetWebRequest(myUri),
System.Net.HttpWebRequest)

If Me.PreAuthenticate Then
Dim creds As System.Net.NetworkCredential =
Me.Credentials.GetCredential(myUri, "Basic")
If Not creds Is Nothing Then
Dim credentialBuffer() As Byte = New
System.Text.UTF8Encoding().GetBytes( _
creds.UserName & ":" & creds.Password)
request.Headers("Authorization") = "Basic " &
Convert.ToBase64String(credentialBuffer)
Else
Throw New ApplicationException("No network
credentials")
End If
End If
Return request
End Function
End Class
End Namespace

Mar 28 '07 #2

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

Similar topics

0
by: Skeptical | last post by:
Greetings, This question is related to Microsoft Reporting Services Web service. I tried asking it in RS groups but no one seems to be knowledgeable enough to answer, so I wanted to try my...
7
by: Peter Afonin | last post by:
Hello, I'm using this code to access a network share from an asp.net page: Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib\") Dim files() As FileInfo = dir.GetFiles("*.eps")...
13
by: david | last post by:
I met the security problem. I have developed the form based security for ASP.NET appliation. However, it seems that my window based client for my Web services application can not access to the...
2
by: Justin Lazanowski | last post by:
I have a windows app that I am writting for some field reps. This app should download and upload specific information to a web service, and cache the information on the local computer when they are...
0
by: nospamthanks | last post by:
Hi, I have an existing web site, which is configured to use forms authentication. I'd like to expose a web service from this site to provide admin services for the site, and expose some server...
18
by: troywalker | last post by:
I am new to LDAP and Directory Services, and I have a project that requires me to authenticate users against a Sun Java System Directory Server in order to access the application. I have found...
3
by: Sylvie | last post by:
My Windows Application has two forms, one form contains a grid (lets say Stock Listing), and the other is a form of one stock, contains some edit boxes for one stock's fields.. Is it possible to...
3
by: richard.martino | last post by:
On Jun 18, 12:57 pm, "Joe Kaplan" <joseph.e.kap...@removethis.accenture.comwrote: ----------------------- Because when I execute: sendmailproxy.SendEmailRequest(sendmail);
8
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service and hosted it in Windows Services. It is working fine. Now I am trying to implement the X509 certificates for message layer security. But it is throwing the following...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.