473,414 Members | 1,686 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,414 software developers and data experts.

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 1612

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

Similar topics

2
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
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
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
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
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
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
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
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
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
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.