Thursday, December 01, 2005

Another Random Web Service Error

I just got this:

"Request is not available in this context"

I discovered shortly after this is down to the web service proxy being out of synch with the content of the asmx service file itself. One to watch out for, particularly if you're creating your proxies manually and not using VS IDE.

Tuesday, November 29, 2005

More Teething Probs...

You may also get

"

The request failed with HTTP status 404: Not Found.



"

Again, this indicates an incorrect address.

Web Service Teething Problems

If you get the following...

"

The underlying connection was closed: The remote name could not be resolved.


"
This means you've specified an incorrect URI for the web service. Check the address and try again. Probably seems obvious, but this has caught me out several times before so this is to help me remember, if nothing else.

You may also come across....

The request failed with HTTP status 404: Not Found.


Again, incorrect address specified.


Monday, November 21, 2005

Creating A Web Service Proxy

Use the following at the .NET command prompt to create a web service proxy (note: perform this operation within the directory that contains your service file).

wsdl /l:cs /o:AppServiceProxy.cs http://localhost/MyWebService/AppService.asmx?WSDL /n:AppSettings

Friday, October 28, 2005

Using Web Response

You can the HTTP WebRequest and WebResponse objects to contact a remote server through your code, send POST data and handle a response.

Below is a method to support this activity. The example code uses a payment gateway service, sending it POST data for a payment transaction and retrieving the response.

private object ProcessHTTPRequest(IPaymentProvider provider, string POSTdata)
{
ASCIIEncoding encoding=new ASCIIEncoding();
POSTdata = "VPSProtocol=2.2&TxType=PREAUTH&Vendor=MyVendor&VendorTxCode=55555&Amount=444&Currency=GBP&Description=TestDesc";
POSTdata += "&CardHolder=Test&CardNumber=000000000000&StartDate=0105&ExpiryDate=1205&IssueNumber&CV2&CardType=Visa&BillingAddress=sdklfjsdf&BillingPostCode=cmdmdm";
byte[] data = encoding.GetBytes(POSTdata);


// Create a new HTTP Web Request.
HttpWebRequest request;


try
{
System.Uri uri = new System.Uri(provider.AbsoluteUrl);
request = (HttpWebRequest)WebRequest.CreateDefault(uri);

}
catch (WebException exRequest)
{
throw exRequest;
}

// Set properties of the request object.
request.Method = "POST";
request.ContentType="application/x-www-form-urlencoded";
request.ContentLength = data.Length;

// *** WRITE THE POST DATA *** //
try
{
Stream newStream = request.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
}
catch
{}


// Create a new WebResponse object.
WebResponse response;

try
{
response = request.GetResponse();
}
catch (WebException exResponse)
{
throw exResponse;
}

string serverResponse = ""; // String for response output.

try
{
// *** READ *** //
// Get the response.
Stream responseStream = response.GetResponseStream();
// Create a stream reader from the returned stream.
StreamReader sr = new StreamReader(responseStream);
// Read the response.
serverResponse = sr.ReadToEnd();
}
catch (WebException exRead)
{
throw exRead;
}
catch (Exception genException2)
{
throw genException2;
}

// Return the response.
return serverResponse;

}

Monday, October 24, 2005

The Global Assembly Cache (GAC)

The Global Assembly Cache (GAC)

The Global Assembly Cache (GAC) is a central repository for storing shared assemblies. The GAC allows multiple versions of the same assembly to be installed concurrently and also prevents different assembly vendors from overwriting each other's assemblies.
The use of the GAC is encouraged for assemblies that will be used by more than one application on the system, and also for assemblies that are expected to be versioned in the future. When an application is launched, Mono extracts the name of the assembly, the version and its public key token and loads the required assembly from the GAC.
The GAC is a black boxed repository of assemblies capable of keeping multiple version/cultures of a same assembly. A strongname is considered a unique entry in the GAC (i.e. the GAC requires all it's assemblies to be strongnamed and signed). Note that the GAC has nothing to do with security! In fact assemblies in the GAC aren't verified when loaded from the runtime. The GAC is for manageability (avoiding DLL hell).

Source: http://www.mono-project.com/Assemblies_and_the_GAC

"The located assembly's manifest definition with name 'MyRootNamespace.MyNamespace' does not match the assembly reference."

"The located assembly's manifest definition with name 'MyRootNamespace.MyNamespace' does not match the assembly reference."

Ahhhh, this one is a joy, isn't it? Just when you think everything is working out fine - your latest dll error-free and nicely compiled, then bam - this lovely little son-of-a-gun comes along.

The error is caused by the assembly reference within your project being 'out of synch' with the assembly itself - i.e. there exists a reference to a different version of the assembly, be it older or newer. This can occur more commonly when you're throwing around new versions of a dll between projects and you forget to update the appropriate assembly reference info.

What to do if this happens? Well, if using VS IDE, simply re-saving should solve it, however if it doesn't, right click the reference under the 'References' folder, select 'Remove' and then add it back in again.

Thursday, October 06, 2005

"Requested registry access is not allowed"

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

[SecurityException: Requested registry access is not allowed.]
Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +473

This is caused by an unauthorised user account trying to write to the event log.


MSDN says:

CAUSE

This problem occurs because the user account that you used to log on does not have sufficient permissions.

See: http://support.microsoft.com/default.aspx?scid=kb;en-us;842795

Thursday, September 15, 2005

You can bind to RadioButtonLists too...

Having messed around for a good part of yesterday with trying to bind some values to a RadioButtonList control and failing miserably, I suddenly realised (after a quick check on MSDN) just how simple it really is.


// Set the properties of the radio button list.

rbl.DataSource = results.Tables[0].DefaultView;
rbl.DataTextField = "Name";
rbl.DataValueField = "ID";
rbl.DataBind();

So much wasted time, but a lesson learnt. Next time I'll consider that databinding might exist, before I come up with some crazy scheme involving Literals...

Wednesday, January 05, 2005

Environment

string pathToLog = Environment.CurrentDirectory + "\\Config\\Rules.xml"; //was --> @"c:\temp\Log.txt";

Environment.CurrentDirectory

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Z