Wednesday, April 04, 2007

Web Services- ASP.Net and Credentials

I have noticed a lot of people getting stuck on some fairly basic stuff when working with ASP.NET web services. Like a lot of things in development, security can quite often trip us up.

If you have configured your ASP.NET web service to use integrated access via IIS you may be experiencing some difficulties in accessing a web service on a corporate intranet. If you are getting the message "Access denied" you most likely have not set the authentication credentials on your web service before making a call to one of its web methods.

Assuming you have an instantiated web service object called ws for our purposes, implement the following code:

ws.Credentials=System.Net.CredentialCache.DefaultCredentials;

This tells the web service who is trying to access it. By default the Credential property is set to null, meaning no credentials are sent through.

Wednesday, March 14, 2007

xsd Command line tool for Visual Studio

There is a perhaps quite underutilized command line tool available for Visual Studio. It is called xsd.exe and is installed in most typical configurations of Visual Studio 2005 (and 2003 for that matter). To use it, simply open a Visual Studio 2005 Command Prompt window (from the Visual Studio -> Visual Studio Tools folder in the start menu). Alternatively you can open the folder C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin substituting your custom install path if necessary.

It is capable of a number of quite useful operations including:

1) The ability to generate XSD schema files from XML files. The syntax for that is simply:
xsd %1
Where %1 is the name of the xml file. This will generate an xsd with the same filename as the xml except with an xsd extension.

2) You can generate sub classed datasets via this method:
xsd %1 /d
Where %1 is the xsd file. This will output similary named class files that provide custom datasets based on the schema provided. The smart bit about this is that hidden primary and foreign keys are added to the dataset transparently. The reason why this is so smart is that is provides a means for you to programatically link nested elements to parent elements. When a typical command like:
MyDataSet.WriteXML(@"c:\out.xml"); or
MyDataSet.GetXML();
the Xml generated adheres to the schema provided during your xsd output. For some of you this may be pretty straight forward but I know some, including myself, who it took a while to figure out how this all fits together.

3) You can also generate classes for the objects, which is probably less useful, but handy for those wanting assistance to quickly create business objects for large schemas. The way to do this is:
xsd %1 /c
The %1 parameter being the xsd schema file.

4) Another useful operation for this command line utility is the ability to convert xdr to xsd. This can sometimes save a lot of effort! To do this:
xsd %1
The parameter %1 being the name of the xdr file (which must have an .xdr extension!).

Note that by default the classes (and dataset classes) that are generated output as c #. You can alter which language these output in by using the /language (or /l) switch. The possibilities are CS (C#), VB, JS, VJS or CPP. You can also instead "provide a name for a fully qualified class implementing System.CodeDom.Compiler.CodeDomProvider". This will let you output in your favourite niche langauge (anyone for IronPython or perhaps even f#?).

There are a bunch of other cool things this utility can achieve but I shall leave the exploration to you.

ASP.NET Label Control Aligning Text

A fellow developer at work today was struggling to find away to perform what should be a fairly simple task. He was attempting to align some text in an asp:label control to the right. As their is no extremely obvious align like property some confusion resulted. After a quick bit of research and trial and error we worked it out.

1) Make sure the asp:label has a fixed width. This way aligning to the right is actually meaningful.

2) In your page_load or other relevant code section insert a piece of code similar to the following:
Label1.Style.Add("text-align", "right");

note that this can also be accessed like so:
Label1.Attributes.CssStyle.Add("text-align", "right");

The attributes element is also worth exploring for your own research, it can provide an enumerator for all keys associated with the current control.

Tuesday, November 21, 2006

Catastrophic Error, Multiple Infopath Forms

An error that seems to be plaguing a number of people occurs during the following scenario:

A user attempts to open a new instance of InfoPath, loading a form that is based on a template that there is already a form open form. When the form attempts to load InfoPath spits back a helpful error: "Catastrophic failure!".

A workaround for this, which I am not convinced is the best solution, is to remove the name attribute from the processing instructions.

So typically you may have a PPI that looks like this:


<?mso-infoPathSolution solutionVersion="1.0.0.562" productVersion="11.0.6565" PIVersion="1.0.0.0" href="file:///\\yourhost\templates\yourTemplate.xsn" name="urn:schemas-microsoft-com:office:infopath:yourTemplate:-myXSD-2006-06-12T01-41-41" ?><?mso-application progid="InfoPath.Document"?>


Change this to:
<?mso-infoPathSolution solutionVersion="1.0.0.562" productVersion="11.0.6565" PIVersion="1.0.0.0" href="file:///\\yourhost\templates\yourTemplate.xsn" ?><?mso-application progid="InfoPath.Document"?>


This will do the trick it seems.

Friday, July 21, 2006

Mismatched Hosts, Binding Drama and BTS 2006 Reconfiguration

Recently, for a frustrating reason, I had to unconfigure a BizTalk server located in the development environment at a client's site. Later, when reconfigured, I came accross an interesting error when I tried to redeploy some of the orchestrations:

Error 6 Failed to add resource(s). Change requests failed for some resources. BizTalkAssemblyResourceManager failed to complete end type change request. Failed to update binding information. The following items could not be matched up to hosts due to name and/or trust level mismatches: Item: 'APS.Search.GetChildDetails.Orch_GetChildDetails' Host: 'BTS_APS' Trust level: 'Untrusted'You must do one of the following:
1) Create hosts with these names and trust levels and try again
2) Re-export the MSI without the binding files and have a post import script apply a suitable binding file.

The symptom of my problem seemed basic enough- when the assembly was attempting to deploy to the BTS server it was utilising a prior binding file that was not configured properly to interact with the reconfiguration. I googled and google-grouped the error and came up with nothing. I assume that the binding file is embedded in the assembly somewhere, but where I do not know! What I did work out was how to solve the problem.

Presumably if you googled the error you just want the damned solution, so here it is- changed the strong key associated with the project and rebuild. This seems to remove whatever binding file was associated with the assembly and allows for smooth deployment, all things being equal.

So if you have any idea where this binding file is actually located, please comment as I'd love to know.

Tuesday, February 21, 2006

Introduction

G'Day Viewers,

I am a .net developer based in Perth, Australia. I intend to use this blog as a place to put the solutions I come up with to the various problems I face. I primarily develop BizTalk based solutions but as expected, I am involved in many other .NET related projects.

Ben Szymkow