Archive for the ‘WCF / Web Services’ Category

WCF RESTful Service URL Cannot be Found HTTP Error 500

June 13, 2012

I am taking my first noob steps into creating a RESTful WCF Service which means you can benefit from all my obvious blunders and mistakes.
Here’s the first one:

Slavishly following the excellent article ‘Create RESTful WCF Service API : Step By Step Guide’ I was shocked to find that I got a HTTP 500 error when accessing the Service URL. The problem was merely that I had omitted the webHttp element from the endpointBehaviour configuration.

In my web.config for the service I had:

endpointBehaviors
behavior name="web"

/behavior
/endpointBehaviors

But what I needed was:

endpointBehaviors
behavior name="web"
webHttp/
/behavior
/endpointBehaviors

So now you know.
Keep on noobing!

Advertisements

Web Service Crashes – Could not load file or assembly ‘xxxx’ or one of its dependencies. There is not enough space on the disk. (Exception from HRESULT: 0x80070070)

October 25, 2010

Semi-Loyal Public,

Got this error with the deceptively self-explanatory error message ‘Could not load file or assembly ‘xxxx’ or one of its dependencies. There is not enough space on the disk. (Exception from HRESULT: 0x80070070)’.

Accidently Correct

Well, the disk was indeed full, so I deleted Megabytes of useless rubbish from the disk and re-ran the app, but annoyingly still got the crash.

This means that the error message was either accidently correct, or that the C#.NET compiler generates error messages by taking a punt on partial information making it behave like it was written by a 2nd year Uni Student as a lab exercise for an Artificial Intelligence course.

Turns out Disk Space had nothing to do with it. The real reason the WebService could not run was because the UserAccount as defined in the Application Pool settings for the WebService did not have permissions to the bin directory of the WebService.

Resolution:

  • Check user for the Web Service in the Application Pool.
  • Give that user Full Control to the Bin Directory for the web application, in this case MyUnrealWebService. which was running under the user ‘NETWORK SERVICE’

Hat Tip to drobar who was kind enough to post the relevant fix at Umbraco.

Visual Studio: Cannot Step Into WCF Service Hosted In IIS

October 25, 2010

If you are reading this then you are probably a complete newbie like myself to WCF. Never mind. We can huddle here together for warmth.

So in my case I had a WCF Service running on localhost under IIS and a Client that consumed that Service running under Cassini. There was a Breakpoint in my Client code on the call to my WCF Method and when I hit that breakpoint and hit F11 then the debugger would step into it as obediently as Frankenstein’s Monster on an assassination mission. I was as smug as a 200kg Tabby Cat locked in a Cream factory over the Christmas holidays.

My client app and my WCF app were in different solutions and open in different instances of VS2008.

Then I made my critical mistake – I went to Lunch.

During my absence tiny invisible super-intelligent Manta Rays from the Planet QUARX sabotaged my apps so that I could no longer step into the WCF code from my client. My Team Lead could not figure out why either.

Well about 96 Google Minutes later I found this hyper-simple solution (remember, we’re newbies here) on TroubleShootingWiki.org.

I slavishly did what they suggested which was in the VS2008 instance hosting my WCF Solution, select Debug from the main menu and…

select process aspnet_wp.exe from the list of available processes, and click the Attach button. You will find this process attached to the debugger. Open the HelloWorldService.cs file and set a breakpoint if you haven’t done so already. Now run the HelloWorldClient program…from another Visual Studio instance…and you will see that the breakpoint is now hit.

Good news: The tiny hyper-intelligent Manta Rays are gone and the Tabby Cat is back. Pass me the Triple Fat thanks.

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

August 5, 2010

This is a commonly encountered problem and there a lot of posts out there on the Greater Google on this, including the solution I am about to tell you. Hopefully this post will add to the solution bandwidth of those experiencing the same issue as I did.

We have a UAT server which is allowed to access the live database. The only explanation I can give you for that is that our Test team are somewhat spoilt. They want to see the effects their changes will make on copies of our real live pages and have convinced management that they must have visibility to up to the second live data and so they do.

The above means that the UAT server uses our PROD Web Services. One fine day after one of our Web Services was updated, it lost connection to the live database. Inspection of the relevant configs showed that the UAT server was wired into the UAT Web Service server (as one would expect) so how it ever accessed PROD database previously I don’t know, but it couldn’t now.

Host File

The Engineers informed me that the UAT server lived in a Test Domain with the other test servers and that this domain had a Domain Controller with an ‘A’ record that defined our Web Service URL as pointing to the UAT Server i.e. mywebservice.company.net always resolved to the UAT Web Service server. Hence updating the host file with a record that read “prod_server_ip_address” mywebservice.company.net would never work as it was overruled by the domain controller.

Engineering Magic

So what the Engies did was take the UAT server out of the Test domain and update the Proxy settings for the server to point to our public Internet Server. They then changed the Firewall Rules to allow Port that our Web Service runs on to get through the firewall (they opened the Port). This then allowed our UAT server to contact the Web Service running on the PROD Web Service server.

In Summary
Open the ports on your Firewall to allow traffic to the Web Service you need.

Credentials Property Missing From WebService Instance

March 1, 2010

Scenario:

You are eating your liver because you have created an Instance of a Web Service which exists in your local project and you want to add custom Credentials to the proxy Instance BUT there is no Credentials property.

So Pretty, So Useless

Your code looks flawless: It looks something like this, but Visual Studio reports there is no Credentials property

_MyWebService = New XMLExtractWebService
_MyWebService.Credentials = New Net.NetworkCredential(WEBSERVICECREDENTIALUSERNAME, WEBSERVICECREDENTIALPASSWORD)

What You Need To Do

Add a Web Reference to the Web Service i.e. Click on the WebReferences folder in the project which is consuming the Web Service and select Add Web Reference. Click on ‘Web Services In This Solution’ and then select your Web Service. Add a Reference name for it. I called my reference MyXMLExtractWebService.

Now update your code as follows, giving the class name of your Web Reference:

_MyWebService = New MyXMLExtractWebService.XMLExtractWebService
_MyWebService.Credentials = New Net.NetworkCredential(WEBSERVICECREDENTIALUSERNAME, WEBSERVICECREDENTIALPASSWORD)

Your Credentials Property is now there.

Why It Works

The Credentials Property only exists on Web Services deriving from created using the Web Services Description Language (WSDL) tool (Wsdl.exe), or created when adding a Web Reference in Visual Studio.NET,

These Web Services derive from the SoapHttpClientProtocol class and have a Credentials property, which can be used to get or set security credentials for Web Service client authentication.

For this wisdom we can thank Madhu in this post in the .NET 247 Forum

Web Service Connection Actively Refused. You are running Cassini.

February 25, 2010

Scenario:
You are eating your liver because when you try to access your Web Service your app crashes with

No connection could be made because the target machine actively refused it

The Stack Trace includes the following:
SocketException (0x274d): No connection could be made because the target machine actively refused it 127.0.0.1:1204]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +239
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +35
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +224

[WebException: Unable to connect to the remote server]

Why the Pain ?

Quite possibly your Web Service is not running in any Web Server. In my case IIS was not set up on my local machine and I am therefore using Cassini, the built-in Web Server with Visual Studio.

BUT

While there was a Cassini process for my Web App there was no Cassini process for my Web Service. The sucker was moribund. No wonder it didn’t work. The solution is to start your Web Service which I did by starting a Cassini process for it.

In Visual Studio:

1) Set StartUp project as WebService
2) Run project (i.e. hit F5)
3) A Cassini Process starts up. This is the one serving your WebService. Never let it stop.
4) Now make your Web project that consumes your web Service your StartUp Project
5) Run it.
6) Another Cassini Process starts up. This one is serving your web site
7) Bob’s your nerdy cousin with the extreme ear wax. i.e. you will now be able to use your Web Service and the horrifying Active Refusal error message is gone.

So to make that clear, if you’re running Cassini, you need one Cassini Process for each Web Service you are consuming plus another Cassini Process to serve your actual Web Site. In my case I have one Web service so I need a total of two Cassini processes running to support my application.

Slightly misleading error message there. Should say “Web Service is not running.” ‘Actively refused’ makes me think of Credentials…and repressed memories about asking chicks out when I was a teenager, stuff like that.

Server Did Not Recognise The Value Of HTTP Header SOAPAction (Or How Not To Add A New WebMethod to an existing WebService)

December 17, 2009

This can come about when your Web Services References file (automatically generated by Visual Studio) is out of sync with your asmx file because you have manually hacked added some Web Methods. Make sure that all your WebMethods have corresponding entries in the Web Service Web Reference file (Reference.vb or Reference.cs).

WARNING: If you are trying to Add a new WebMethod to an existing Web Service do not do what I did below. It will only consign you to a Journey of Pain.

I am maintaining an app. that has a large WebService that operates on a group of DataSets. Each DataSet has three WebMethods associated with it. I created a new DataSet, cut and pasted the three standard Web Methods the app. needs to operate on the new DataSet and manually hacked the Reference.vb file to set up the calls to Invoke the Web Method and the Async versions of the Web Method i.e this stuff:

Public Function GetPreviewSEODataSetByDomain(ByVal domaincode As Integer) As System.Data.DataSet
Dim results() As Object = Me.Invoke(“GetPreviewSEODataSetByDomain”, New Object() {domaincode})
Return CType(results(0), System.Data.DataSet)
End Function

BUT I only manually hacked in the necessary Invokes for ONE of the WebMethods, not all three. For some reason this caused the SOAPAction error. When I removed the other two WebMethods from the asmx file the error went away.

If the above does not pertain to you, make sure you haven’t messed up the Web Service Namespace.

Now here’s what I should have done:

How To Add A New WebMethod to an existing WebService

1. Add the new Web Method to your asmx file. Decorate with WebMethod attribute of course.
2. Get Visual Studio to update the WebReference file, Reference.vb/Reeference.cs. This file does not belong to the Web Service per se. Rather it belongs to the Project which calls the WebService. Visual Studio generates it when you add the Web Reference.

To update it, locate the reference to your Web Service in your calling Project’s Web Reference folder, right-click and select Update Web Reference from the Context Menu. No more hacking, everything works, pain in cranium stops. To celebrate, I recommend making yourself a free instant coffee from the staff room. That’s what I did.

Update: Jul-23-2010
If you do the Update References thing and you don’t see your new Web Method, check the WebServices Properties by right-clicking on your Web Reference and going to ‘Properties’. Check out the URL for the Web Service and make sure it’s correct.

In my case the Properties had the URL of our PROD Web Service which didn’t help me much while I was adding a new method to the DEV Web Service. So I changed the PROD URL for the DEV URL and UpdateReference did its thing.