473,503 Members | 11,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access denied

whoops - I should have posted this to CSharp not ASPNET:

Hi,

I am using a 3rd party product to create dynamic web service proxies
(downloaded from www.thinktecture.com).

My problem is that it doesn't work if Anonymous Access is turned off. I
know, from searching, that this is to do with Credentials but I just
can't seem to find where to fix it.

First it builds wsdl string (I added the 2 Credentials lines):
WebRequest req = WebRequest.Create(uri);
req.Credentials = System.Net.CredentialCache.DefaultCredentials;
WebResponse result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
Encoding encode = Encoding.GetEncoding("utf-8");
StreamReader sr = new StreamReader(ReceiveStream, encode);
string wsdlSourceValue = sr.ReadToEnd();
sr.Close();
return wsdlSourceValue;

Then it builds an assembly:
StringReader wsdlStringReader = new StringReader(strWsdl);
XmlTextReader tr = new XmlTextReader(wsdlStringReader);
ServiceDescription.Read(tr);
tr.Close();
// WSDL service description importer
CodeNamespace cns = new CodeNamespace(CodeConstants.CODENAMESPACE);
sdi = new ServiceDescriptionImporter();
// check for optional imports in the root WSDL
DiscoveryClientProtocol dcp = new DiscoveryClientProtocol();
//(I added this credentials line)
dcp.Credentials = System.Net.CredentialCache.DefaultCredentials;
dcp.DiscoverAny(wsdl);
dcp.ResolveAll();
foreach (object osd in dcp.Documents.Values)
{
if (osd is ServiceDescription)
sdi.AddServiceDescription((ServiceDescription)osd, null, null);
if (osd is XmlSchema)
{
// store in global schemas variable
if (schemas == null) schemas = new XmlSchemas();
schemas.Add((XmlSchema)osd);
sdi.Schemas.Add((XmlSchema)osd);
}
}
sdi.ProtocolName = protocolName;
sdi.Import(cns, null);
// change the base class
// get all available Service classes - not only the default one
ArrayList newCtr = new ArrayList();
foreach (CodeTypeDeclaration ctDecl in cns.Types)
{
if(ctDecl.BaseTypes.Count > 0)
{
if(ctDecl.BaseTypes[0].BaseType == CodeConstants.DEFAULTBASETYPE)
{
newCtr.Add(ctDecl);
}
}
}
foreach (CodeTypeDeclaration ctDecl in newCtr)
{
cns.Types.Remove(ctDecl);
ctDecl.BaseTypes[0] = new CodeTypeReference
(CodeConstants.CUSTOMBASETYPE);
cns.Types.Add(ctDecl);
}
// source code generation
CSharpCodeProvider cscp = new CSharpCodeProvider();
ICodeGenerator icg = cscp.CreateGenerator();
StringBuilder srcStringBuilder = new StringBuilder();
StringWriter sw = new StringWriter(srcStringBuilder,
CultureInfo.CurrentCulture);
if (schemas != null)
{
foreach (XmlSchema xsd in schemas)
{
if (XmlSchemas.IsDataSet(xsd))
{
MemoryStream mem = new MemoryStream();
mem.Position = 0;
xsd.Write(mem);
mem.Position = 0;
DataSet dataSet1 = new DataSet();
dataSet1.Locale = CultureInfo.InvariantCulture;
dataSet1.ReadXmlSchema(mem);
TypedDataSetGenerator.Generate(dataSet1, cns, icg);
}
}
}
icg.GenerateCodeFromNamespace(cns, sw, null);
proxySource = srcStringBuilder.ToString();
sw.Close();
// assembly compilation
string location = "";
if(HttpContext.Current != null)
{
location = HttpContext.Current.Server.MapPath(".");
location += @"\bin\";
}
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.Xml.dll");
cp.ReferencedAssemblies.Add("System.Web.Services.d ll");
cp.ReferencedAssemblies.Add("System.Data.dll");
cp.ReferencedAssemblies.Add(Assembly.GetExecutingA ssembly().Location);
cp.ReferencedAssemblies.Add(location +
"Thinktecture.Tools.Web.Services.Extensions.Messag es.dll");
cp.GenerateExecutable = false;
cp.GenerateInMemory = false;
cp.IncludeDebugInformation = false;
cp.TempFiles = new
TempFileCollection(CompiledAssemblyCache.GetLibTem pPath());
ICodeCompiler icc = cscp.CreateCompiler();
CompilerResults cr = icc.CompileAssemblyFromSource(cp, proxySource);
if(cr.Errors.Count > 0)
throw new
DynamicCompilationException(string.Format(CultureI nfo.CurrentCulture,
@"Building dynamic assembly failed: {0} errors - {1}",
cr.Errors.Count,cr.Errors[0].ErrorText ));
Assembly compiledAssembly = cr.CompiledAssembly;
//rename temporary assembly in order to cache it for later use
CompiledAssemblyCache.RenameTempAssembly(cr.PathTo Assembly, wsdl);
return compiledAssembly;

It creates a proxyInstance (as an object where objTypeName is passed
in):
foreach (Type ty in ProxyAssembly.GetTypes())
{
if(ty.BaseType == typeof(SoapHttpClientProtocolExtended))
{
if(objTypeName == null || objTypeName.Length == 0 || ty.Name ==
objTypeName)
{
objTypeName = ty.Name;
break;
}
}
}
Type t = ass.GetType(CodeConstants.CODENAMESPACE + "." + objTypeName);
return Activator.CreateInstance(t);

And it uses this to call the method:
MethodInfo mi = proxyInstance.GetType().GetMethod(methodName);
object[] paramsArray = (object[])methodParams.ToArray(typeof(object));
object result = mi.Invoke(proxyInstance, paramsArray);
But the Invoke fails with Access denied. Using this base (because I
have downloaded it and have not had the expertise or time to fully
understand it) - how can I get this to work with Anonymous Access
turned off. I imagine if I can get an IWebProxy object from
proxyInstance I could try setting the credentials of that before Invoke
but I'm not sure how to get that object.

Any ideas>

TIA
Phil

Nov 17 '05 #1
0 1616

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

Similar topics

2
3040
by: calfdog | last post by:
Hello, Does anyone know a workaround for calling fireEvent. With the latest from Microsoft OS XP2 and Hot fixes to IE it now gives an "access denied" error in Python when called. Here is what...
0
2936
by: Steve | last post by:
Hi, Yesterday I signed up for another dedicated linux server with the hosting company I use and I am having problems getting MySQL 4.1.3 working on it. I've tried just about everything I can...
9
6300
by: | last post by:
Hi All, I have allready tried to ask a similar question , but got no answer until now. In the meantime, I found, that I cannot understand some thread-settings for the Main() function . If I use...
0
3519
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the...
16
7361
by: Brad | last post by:
After compiling my asp.net project I'm receiving a "BC31011 - Access is denied" error when attempting to run or debug. The only thing that seems to resolve problem is IISReset. After a reset my...
12
3069
by: Ron Weldy | last post by:
I have a test server runinng 2003/IIS 6 with a mixture of asp and asp.net files. On my workstation I have a share set up to the folder where the web files reside. I am just doing quick and dirty...
3
7972
by: Shailesh Humbad | last post by:
I figured out what was causing the "Access is Denied" error when calling functions from referenced DLLs in my service. I've tried to be very detailed, so bear with me. It turns out that...
3
7945
by: David Thielen | last post by:
Hi; I created a virtual directory in IIS 6.0 and my asp.net app runs fine. But when it tries to write a file I get: Access to the path is denied. - C:\Inetpub\wwwroot\RunReportASP\images ...
8
6032
by: Jeremy Ames | last post by:
I am trying to move an application from my system to a new test system. I really should have tried an easier program first, but I didn't really have a chance. My application was originally written in...
0
3927
by: Andy | last post by:
Thanks Peter, I thought I'd give an update on this problem. My application had 2 assemblies that contained classed for the Data access and business logic layer. It was on one of them that I was...
0
7207
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
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7015
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
7470
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...
1
5026
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...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.