Problem connecting to a java webservice
Date: 08/19/06
(C Sharp) Keywords: java, security, web
I am writing a simple c# app in Visual C# 2005 Express to connect to a java webservice. I am basing my code off of an Visual Basic 2003 app that someone else wrote that doesn't do all that I want. My problem is I keep getting the following error messages when I try to use the service.
A first chance exception of type 'System.Net.WebException' occurred in System.Web.Services.dll
The request failed with HTTP status 404: Not Found.
public bool Work(string request, string response, string environment)
{
StreamReader fileStream = new StreamReader(request);
string content = fileStream.ReadToEnd();
VitalWS.WebServiceFacadeService webService = new VitalWS.WebServiceFacadeService();
string cmdLine;
if (environment != "veasm" || environment != "veasm2")
{
cmdLine = "https://" + environment + ".mreports.com/ws/services/webServiceFacade";
}
else
{
cmdLine = "http://" + environment + ".mreports.com/ws/services/webServiceFacade";
}
webService.Url = cmdLine;
X509Certificate privateKeyCertificate = null;
X509CertificateStore store = new
X509CertificateStore(X509CertificateStore.StoreProvider.System,
X509CertificateStore.StoreLocation.CurrentUser,"My");
bool open = store.OpenRead();
foreach (X509Certificate certificate in store.Certificates)
{
if (certificate.Subject.IndexOf("wamueast") > 1)
{
privateKeyCertificate = certificate;
}
}
if (store != null)
{
store.Close();
}
Console.WriteLine("Certificate CN:" + privateKeyCertificate.Subject);
webService.RequestSoapContext.Path.MustUnderstand = false;
X509SecurityToken digitalSignatureSecurityToken = new X509SecurityToken(privateKeyCertificate);
webService.RequestSoapContext.Security.Tokens.Add(digitalSignatureSecurityToken);
Signature digitalSignature = new Signature(digitalSignatureSecurityToken);
digitalSignature.SignatureOptions = SignatureOptions.IncludeNone;
digitalSignature.SignatureOptions = SignatureOptions.IncludeSoapBody;
webService.RequestSoapContext.Security.Elements.Add(digitalSignature);
string webResponse = null;
bool result = false;
try
{
webResponse = webService.executeService(content);
return result;
}
catch (System.Net.WebException we)
{
Console.WriteLine(we.Message);
return result;
}
}
Can anyone offer a suggestion why this does not seem to work? I know that the url for the webservice is correct because I can use the buggy VB.Net app to get a response.
Thanks
Source: http://community.livejournal.com/csharp/73666.html