We have a WCF service and Silverlight app that's been running for a few months now and it's been running fine until today. For some odd reason, there is one method in the service that is giving me an error every time I call it. I've gone so far as commenting out everything the method does, but as soon as I call it from the silverlight app I get that stupid error:NotFound message.
Here's the kicker though... if I run the silverlight app and WCF service on my local machine it runs just fine. It's only when the service is running live on our hosting company's server that I get the error.
Does anyone have ideas??
Getting the error NotFound in a Silverlight Client calling a WCF Service normally means that the service method threw an exception. Without further details we won't be able to help.
I believe I have found the problem. The class that I'm passing through as a parameter looked something like this:
public class MyClass
{
[DataMember]
private string Name = "";
public string _Name
{
get
{
return RegionNameName;
}
set
{
RegionNameName = value;
this.NotifyPropertyChanged("_Name");
}
}
}
The [DataMember] attribute placed on top of the private property seems to have caused the problem. Strange thing is that it did work for the last few months.
Anyway, the guy who wrote it has left the company. So I'll be working through the whole thing now. Not quite what I had in mind for work today.
Related
I promise I searched for the answer...
My application consist of both a Mobile backend in azure and a Web-client application that makes calls upon this back-end.
I have run across a bizarre bug that creates 404 not found errors when calling a Http Get function on my backend.
The bizarre part of this issue is that the error is random. It is probably a %50 chance that I might get a 404 or a 200 ok response from the server. This only happens on one specific method that was recently added.
I am wondering if breaking the back-end into instances might have created a non-identical copy of my app.
I removed the instance, and the specific api I have been calling is not longer available on the published version it is visible while running on debug.. I get 100% error on the published version now.
What is wrong with azure? cleaning and rebuilding the back-end does nothing.
[Route("api/UserProject/{projectId}")]
[HttpGet]
public HttpResponseMessage GetUserProjectByProjectId(int projectId)
{
//Get all UserProject
List<DTO.User> userList = new List<DTO.User>();
DataTable UserdataTable = SqlHelper.ExecuteDataset("dbo.UserGetByProjectId", projectId).Tables[0];
if (UserdataTable.Rows.Count > 0)
{
foreach (DataRow dataRow in UserdataTable.Rows)
{
DTO.User u = new DTO.User();
Map.DataToObject(dataRow, u);
userList.Add(u);
}
}
return this.Request.CreateResponse(HttpStatusCode.OK, userList);
}
going to the api/help page on Debug the UserProject route works and is shown in DEBUG mode, but as soon as I publish the app the UserProject function is not longer anywhere to be found.
Wow I finally fixed it. I did the one thing I though would be useless and it worked.
I restarted the service from the azure portal....
My opinion: I guess the created intances where the ones working of the latest version while the original was unable to be updated and the only way to make the original update was to restart the whole thing.
I really don't know why this happened, if you guys want to comment on this please do so.
I recently made a WCF service in C# and hosted it on a server running IIS 8.
Everything worked perfectly when testing locally and I was able to test all of my methods with success. My issue comes when I try to add a service reference to that WCF service in a separate project, the only methods it exposes at this point are async methods even though I never implemented any of my methods as async.
An example of a method would be:
public string getName(User user)
{
return user.name;
}
Something as simple as that would work when I tested it in Visual Studio, but when I host it in IIS and try to add a service reference, the only method I can seem to call or have access to is:
getNameAsync
Why would it do this even though I never implemented it as async in the first place? On top of that, I cannot uncheck "generate methods for async" when I add the service reference in the first place.
Any ideas?
Edit: For reference, I am trying to test these methods inside of a Windows 8.1 app that references the service.
This is how the code is generated. Normally you will find also and event called GetNameCompleted for which you subscribed in the client code like that (after creating a the method ClientGetNameCompleted):
client.GetNameCompleted += ClientGetNameCompleted ;
In this method you will use the service result. something like that:
private void ClientGetNameCompleted (object sender, GetNameCompletedEventArgs e)
{
if (e.Result != null)
{
// use the e.Result that contains the returned data;
}
}
I have a Windows Service that hosts a WCF service and I am successfully able to connect to it using WCFTestClient and a Custom Client. The windows service is based upon what used to be an exe, but since the program will be used for a long running process on a server, the service is a better route. The problem is that I cannot access static variables in the application from the WCF service.
In the .exe (I switched this to a .dll which is the server application) I use a global class implemented as such:
public static class Globals
{
....
}
This holds references to the major parts of the program so that if any part needs to reference another I can use the syntax Globals.JobManager.RunJob().
The problem that I am encountering is that the WCF service is not able to reference Globals at run-time. One example of where I need this to be done is in the GetJob method:
public class ConsoleConnection : IConsoleConnection
{
public string[] RetrieveJobList()
{
string[] jobs = Globals.JobManager.GetAllJobNames().ToArray();
return jobs;
}
}
This method returns null when tested in WCFTestClient and throws an exception in the created client.
I believe this issue to be caused by the way the Windows Service, WCF Service, and the application DLL are initiated. The current method is such:
public class ETLWindowsService : ServiceBase
{
....
protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
}
Globals.InitializeGlobals();
serviceHost = new ServiceHost(typeof(ConsoleConnection));
serviceHost.Open();
}
....
}
Here the Windows Service starts, Calls the Globals.InitializeGlobals() that creates all the necessary parts of the application, then starts the WCF service (If this is the wrong way to do this, let me know. I'm piecing this together as I go). I'm assuming that these actions are being done in the wrong order and that is the cause of the problems.
Do I need to have the Windows Service create the WCF Service which in turn creates the application (this doesnt make sense to me), or do I have the Windows Service create the application which then creates the WCF Service? Or is there a third option that I am missing?
The application is in a .dll with the WCF in a separate .dll
I totally agree with Andy H.
If I review this kind of code, I won't try to make the stuff work with the global static variable (even if in the end this is probably possible). A static global class is smelly. First of all, I will figure out to make it work without it.
There are several solution: dependency injection, messaging communication, event driven...
To help you: a long running process in a web service is very common, youy have a good description
here. But in any case, it never uses a static class to synchronize the jobs :)
Improve your design, and you will see that your current problem won't exist at all.
I have created a simple Web Method, and I hosted it at IIS 7 in my virtual machine (Windows Vista Ultimate), as shown below
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
Then, I write a simple code to consume the web service, as shown below
static void Main(string[] args)
{
WebTest.Service1 ss = new TestConsumeWeb.WebTest.Service1();
Console.WriteLine(ss.HelloWorld());
}
The first time when i tried to used this web service, it works fine. However, it shows no luck on second attempt. In order to let the web service to work again, I found two ways,
restart the IIS Server, but its impossible to restart the IIS from time to time
Wait for a relatively long time (around 20 minutes) and it again works for only one time.
Can someone tells me what could possibly went wrong? I have listed several possibilities but I'm not sure whether they are the problems.
IIS installation problem?
Asynchronous web method should be used?
Problem with IIS configuration?
Problem with the coding?
Something has to be done in Web.config file?
I really need your help if you could, thanks in advanced..
The problem just pointed by Mr Rajesh Subramanian
Under the "application pools" node in IIS Manager, followed by "advanced setting", the default value for "Maximum worker processes" is by default set to "1"
Changing from "Web Reference" to "Service Reference" in client side has worked charm and I don't know why, but its the solution in my case
Once again, thanks Mr Rajesh Subramanian for saving me lots of time!
I'm attempting to recycle an app pool on IIS6 programmatically through a web application. I have searched all over the net and found a bunch of solutions (Most involving impersonation) but none of them seem to work. The most common error I get is E_ACCESSDENIED despite entering a valid username and password. Can anybody point me in the right direction?
The solution I use for this sort of thing (Where you're trying to run a process from ASP.NET that needs administrative privileges) is the following:
Write whatever you need done as a Self hosted WCF service. Preferably an Http REST Service, so it's easy to call (even using just a browser for testing)
Make sure you service is run using an administrator account. You can use the task scheduler to make sure the service is running at all times as well as run using an Administrator account.
Execute methods on the service from your ASP.NET application using a WCF Client
And it works all the time no matter what "process" I'm trying to run from within an ASP.NET application.
Now as far are the details (code) is concerned let me know if you need help. The code below
is the code you'd have in a console application in order to make it a self hosted WCF Service.
In this case it's an Http service listening on port 7654.
static void Main(string[] args)
{
var webServiceHhost = new WebServiceHost(typeof(AppCmdService), new Uri("http://localhost:7654"));
ServiceEndpoint ep = webServiceHhost.AddServiceEndpoint(typeof(AppCmdService), new WebHttpBinding(), "");
var serviceDebugBehavior = webServiceHhost.Description.Behaviors.Find<ServiceDebugBehavior>();
serviceDebugBehavior.HttpHelpPageEnabled = false;
webServiceHhost.Open();
Console.WriteLine("Service is running");
Console.WriteLine("Press enter to quit ");
Console.ReadLine();
webServiceHhost.Close();
}
AppCmdService is a WCF Service class that looks like this (in my case). In your case you probably don't need a response from your service. In my case I'm getting a Json response. The actual implementation of what it is you're trying to do will be different obviously. But I'm assuming you already have that piece worked out. So simply call a method of that class from here.
[ServiceContract]
public class AppCmdService
{
[WebGet(UriTemplate = "/GetCurrentExcutingRequests/?", ResponseFormat= WebMessageFormat.Json)]
[OperationContract]
public IEnumerable<ExecutingRequestJson> GetCurrentExcutingRequests()
{
return CurrentExecutingRequestJsonProvider.GetCurrentExecutingRequests("localhost");
}
}
On your ASP.NET side, you don't really need a WCF client. All you need is a way to make an http call to the service. So you can simply use HttpWebRequest to make the call out to your service, which in turn execute your process.
Hope all of this makes sense?
Maybe this SO question helps you. There are several solutions (also for IIS6):
Restarting (Recycling) an Application Pool
IMHO the best you could do is to decide to go with a concrete approach an then when you run into an exception, to ask a concrete question with the source code of your approach. Otherwise it's just very vage to answer your question.