WCF service deployed to Azure - wcf

I have create a WCF Service Web Role project.I can consume the service locally. But I am having issues trying to deploy the service on the azure cloud. After starting the webrole it justs kepps going in a loop where it init then stops. I have not made any changes to the default WebRoleclass that was added automatically. Can anybody point me to some samples or examples of WCF being deployed to azure

The behaviour you're seeing occurs when the instance errors in the OnStart or Run. The usual diagnostics error trapping hasn't had a chance to start yet so this is a difficult problem to debug. You might try adding error trapping inside this functions that writes the error details out to either a blob or a queue so that you can see what is actually happening.
Having said that, with code that works in the dev fabric, but continues to cycle when deployed to live, the first thing to check is that all of the references have the appropriate "Copy Local" property set. Anything that is part of the framework or Microsoft.WindowsAzure.ServiceRuntime will need to have Copy Local to false, everything else should be set to true (third party assemblies an the like). If this is a web role and you're using MVC, you'll need to check that System.Web.Mvc has Copy Local set to true as well as this is not included as part of the standard framework deployed in Azure.

Have you looked at the Known Issues information on the WCF Azure code page? There's a patch that's needed, as well as a tweak to the service behavior. Hopefully this will help you.

I just found out the root of the problem. It was caused by one of my projects having the target platform set to x86. Seems like it does not support x86 build assemblies which can be a problem

Related

Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener

While using Windows Azure Table Storage in WCFService WebRole, tried to create CloudStorageAccount by the following way:
storageAccount =
CloudStorageAccount.Parse(Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting("[Setting name]"))
Get exception:
ConfigurationErrorsException "Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35."
MSDN help says that 1) Visual Studio must be run as an administrator. 2) A role must be running under full trust (change the .NET trust level option to Full Trust).
All Done, but I still have the same exception.
One thing that can cause this error is running the web role itself, instead of running the containing cloud project. If this is the issue, you could fix it by ensuring that the cloud project is set as the startup project for debugging, and not the web role.
It's possible, and sometimes useful, to run the ASP.NET project that defines the web role on its own. This can be a lot quicker than running things in the Azure Compute Emulator. It may also enable you to develop your project without having to run VS elevated. Also, I've found that the emulator tends to cause Visual Studio to report an invalid memory access error from time to time, at which point you need to restart VS. Running the web role directly avoids all these problems.
However, there are some things that can prevent this from working, and the exception you describe is a symptom of one of these problems. If your web role's Web.config includes configuration for Azure's DiagnosticMonitorTraceListener (and Visual Studio adds that by default when you create a web role) then the first thing that tries to generate trace output will crash with the error you describe if you run outside the emulator. And as it happens, retrieving a setting from the CloudConfigurationManager appears to do this.
This isn't peculiar to the CloudConfigurationManager by the way. All it's doing is producing some trace output. VS configures web roles to send all trace output to the Azure diagnostic listener, and because that listener can only run in either the compute emulator or an actual Azure instance, the first thing that tries to produce trace output will crash. CloudConfigurationManager is a common candidate because it happens to produce trace output, and it typically gets used early on when a role starts up. But in principle, anything that produces trace output could hit this exception.
A simple way to avoid this is to remove the relevant section from the configuration file. When you create a new web role, Visual Studio adds a <system.diagnostics> section that configures the default trace output to go to the Azure diagnostic listener. You could just comment that out. That will enable you to debug the web role directly in Visual Studio without using the compute emulator (assuming you aren't doing anything else that depends on being in a role environment).
Of course, the problem with that is that you'll no longer get any diagnostic traces when running in Azure. One way to solve that is to move the relevant configuration to the Web.config.Release file (adding the necessary xdt: attributes).
This change will also stop the Azure diagnostic trace listener from running when you use the local compute emulator. (That's less of a problem, because the trace messages will still appear in the debugger. It just means you won't get persistent copies of the traces copied to table storage like you would when running for real.) The obvious way to fix this would seem to be to make a similar modification to Web.config.Debug (or to run the release build in the emulator), but there's a snag: apparently cloud projects do not apply configuration file transforms when packaging for the emulator by default. Fortunately, you can fix this: http://blog.hill-it.be/2011/03/07/no-web-config-transformation-in-local-azure/ shows how to enable transforms for local debugging in the compute emulator. (Transforms are never applied when debugging an ASP.NET project directly from within VS, by the way.)
I've found that this error is caused by the wrong version in your web.config
Ie., you may not have
Version=1.0.0.0
Microsoft.WindowsAzure.Diagnostics is up to version 1.8.0.0 as of now
Try updating to the current version
Remove the lines in Web.config < add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener

Want to deploy WCF web service on Azure platform

I want to deploy my WCF web Service on Azure plateform.
I have created a Storage account for my website, and also created a cloud Service and uploaded my package file and config file to the staging site.
But while uploading, The message displays
'Your staging deployment is starting. Hang on, the page will refresh once the deployment begins.'
I am waiting sice 2-3 hours and not getting the desired output.
Am I doing correctly? Or is there anything that I forgot?
Please Help...!
Most likely there is a problem in your code or the packaging that is causing the role to continuously restart. This is a fairly common problem, but there are a lot of possible causes (missing an assembly reference, an uncaught exception, the Run() method is exiting, a Startup Task is failing, or many other things). You need to gather more information to know exactly what the problem is and how to fix it.
There are many threads here on SO about this topic. There's also a Microsoft post discussing how to diagnose this type of issue. Those are good places to start.

WCF service operations not updated

I´m creating a new WCF service. I initially had only three operations. But after some time I decided to add two more. This operations doesn't appear in the Microsoft test client, neither in the list of operations when I try to add a service reference from my WPF client. Also I tried to comment one of the initial operations. It still apears in the Microsoft test client and can be invoked. I Tried also delete the dlls generated by the service and regenerate again. No luck. There are some kind of "cache" where Visual Studio stores the WCF services libraries that I can delete?
UPDATE: I'm working with the service running in the ASP.NET devolopment server.
You need to understand the order in which things happen.
You change your code, adding methods with [OperationContract] on them, or removing them, or changing their parameters or return values.
You then must build your service, producing a .DLL that contains the changes.
You must then deploy the changed DLL to the server it's going to run on
You must then restart the service (this may happen automatically depending on the server. For instance, IIS will recycle the service when it sees that the DLL changed)
You must then update your client, either the WCF Test Client, or "Add Service Reference", or the equivalent.
This last will have the effect of sending a request to the service for the new metadata or WSDL. Only then can the client see the changes you made to the definition of the service.
I don't know why, but I created a new project and copied the definitions of the operations from the problematic project and the problem is gone. One case more for Microsoft mysteries.
Make sure you are updating the services after adding the new operations.
Also make sure they have the attribute [OperationContract].
One thing we have discovered is that when you deploy the dlls that they must be in the bin, and cannot reside in the debug or release folder.
For me worked: just rebuild the wcf project
Did you close the client connection in client side
as showing your service
class Test
{
static void Main()
{
LocationClient client = new LocationClient();
// Use the 'client' variable to call operations on the service.
// Always close the client.
client.Close();
}
}
SOLUTION HERE :
Make sure your dataContract does NOT contain any enum
(You can use integer instead)
Be sure to reference a project in the solution and not a dll on your disk
Remove your "bin" and "obj" folders
Recompile
In IIS recycle the application pool
In IIS restart your service
In IIS "Browse" your service
=> You got it

FluentNHibernate blows up in Windows Service but not website

I've got a class library doing all my NHibernate stuff. It also handles all the mapping using Fluent NHibernate - no mapping files to deploy.
This class library is consumed by a number of apps, including a Windows Service running on my computer. Although it works fine in all my web apps, the Windows Service gets this when it tries to use NHibernate:
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at Kctc.NHibernate.KctcSessionFactory.get_SessionFactory() in C:\Kctc\Trunk\Kctc.NHibernate\KctcSessionFactory.cs:line 28
...more stack trace...
I have checked for an InnerException and there doesn't appear to be one. I have no idea what the PotentialReasons collection is, and Google doesn't seem to be forthcoming either.
This is my dev machine, so when I'm working on my web apps they run locally (i.e. using the web server in Visual Studio). The fact that the Windows Service and my dev web apps are running on this same machine suggest it's not to do with trust settings or what have you.
Can anyone suggest what I should try? This is one of those ones where I'm so stumped I can't even think of how to get more information about the problem.
Just a wild guess. NHibernate picks up the hibernate.cfg.xml file from the execution directory. Did you configure the execution directory of the service that it can find this file?
I've found out what the problem is. The Service did not deploy with the required NHibernate.ByteCode.LinFu.dll.
I appear to have an ongoing problem with the Visual Studio compiler not always copying indirect dependencies (i.e. dlls required by class libraries required by the app) into the output folder during the build. I should have thought of this sooner really.
Thanks for racking your brains on my behalf guys.
I bet the name of the connection string is missing from the app.config. For me that message is almost exclusively a missing connection string.
Are you targeting the same database or could it be some sort of schema mismatch between databases?
Could it be authentication issues on the service like you use windows authentication where it can't be used (or the sql authentication that doesn't work)?
It's hard to tell when there is no code, just an exception!
EDIT Are you ever using HttpContext, HostingEnvironment or anything else specific to "web"?

Update service reference not working

I'm using Visual Studio 2008 and have a WCF client working against a WCF service. They are both located in the same Visual Studio solution. After I've made a change in my WCF contract, I want to update the service reference on the client so that changes made to the contract is also made in the proxy.
My problem is that the proxy code is not re-generated.
When I select to update the service reference, the following happens:
A dialog with the title "Updating service reference 'name-of-reference'" is shown. This dialog has a progress bar.
The progressbar moves and the status text in the dialog is changed to "Updating configuration"
The progressbar moves a bit more, and the status text is chnaged to "Configuration update complete"
The dialog doesn't show the text "Generating \something\" (can't remember the exact wording) which I would expedct.
If I delete the service reference and add it again, the proxy is properly generated. I add the service using the exact same settings as before, so I don't think it's a issue I can solve by changing the service reference configuration on the client.
One thing I suspect may be the problem is that I've renamed the default wsHttpBindings in app.config. I've also renamed the default endpoints. The reason behind this is that I need more than one endpoint and having one named 'some-default-name' and one with my own name is just confusing.
The problem with deleting the service and adding it again is that Visual Studio adds a new binding in app.config (among other things) which should not be there.
Anyone seen this problem before? Anyone knows of a solution to it?
When we have had this problem it has usually been one of these errors:
The size of the contract has increased, and is now so large that the WCF configuration does not allow it to be transferred.
A new class has been added to a WCF Interface and that class is not marked as serializable.
There is a compile error that stops the code from building and it therefore uses the old dll
I've run into this problem with the following conditions:
Our workstations are connected to an Active Directory domain (nearly everything uses Windows Authentication)
The service reference I'm trying to update is hosted on localhost, and is running under IIS Express (so the Application Pool user is running as the developer's personal domain user account)
Another developer has added or updated the reference to the project more recently than me.
The only way I have figured out how to workaround this issue is to edit the configuration.svcinfo file for that service reference (you will need to show all files for the project to see it in visual studio), locate the following section:
userPrincipalName value="user#domain.com"
and change the user to my own domain user. After saving the file, I have no trouble updating the reference until another developer updates the service reference (likely using the same workaround). Unfortunately, I haven't been able to figure out a permanent solution to this issue.
My error was that I forgot to add the OperationContract attribute.
In my case the problem was that the previous developer had added the service reference using his machine name rather than localhost. So when I told Visual Studio to update, it connected to his machine, which did not have the changes. I modified the service reference files and replaced his machine name with localhost and it was able to update the reference.
I had this problem too. Deleted the service reference and recreated it again.
My problem was that I had two methods with the same name. Everything builded fine, but I couldn't update service reference. When I tried to start just the WCF service, the error pops up.
Two easy steps to solve that:
Run Service, then stop it.
Update service reference.
Highlight the service as the active project, F5 to run it in VisualStudio, it will start up in the service test app. Stop debugging. Then try to update your service reference - worked for me.
I know this solution is a bit late, but after trying the posted solutions with no success, this worked:
When you create a WebService, it generates a .dll file that you reference as your service reference. This .dll is (as most know) not recreated everytime you make changes to the .SVC file. You can see this if you go and view the date modified property of the web service .dll file, in my case it was three hours old!
My solution was to make appropriate changes to the service contact, save it, and re-build the project which will cause it to recreate all the .dll's reflecting the changes you made to the service contact file (.svc).
After this, update the service reference on the client app, and the changes are evident.
Spades
I had the same problem. Modified some of the data contracts. Tried to "Update Service Reference" and did not see the change. Dropped and re-added the service. Still didn't see the change when writing code in the client. Opened my client with Reflector and saw the service types had the change! So why was intellisense still showing old properties? Restarted Visual Studio and the modifications finally showed in intellisense.
I had the same problem, this by me it was caused by GIT Merge Conflict, i was missing the following code from my csproj file
<ItemGroup>
<None Include="Service References\<SERVICE NAME>\Reference.svcmap">
<Generator>WCF Proxy Generator</Generator>
<LastGenOutput>Reference.cs</LastGenOutput>
</None>
</ItemGroup>
I have added this onder the line of Reference.svcmap
Another solution to these kinds of problems is if your namespaces get jumbled in referenced projects that both consume the service. So:
ProjectA - Consumes ServiceA
ProjectB - Consumes ServiceA, Has Reference to ProjectA
If you change ServiceA and update ProjectB, sometimes the namespaces can can change to look at ProjectA's version of the service.