I have a WCF Service which is hosted in my Web Application. Both are hosted under the same virtual directory. Don't they run under the same Application Domain and share the HttpContext?
I added a new item to my cache from within the WCF service:
HttpContext.Current.Cache["FirstName"] = "Will";
How could I access this value from the web page?
I tried the below after calling the WCF web service but it was null:
HttpContext.Current.Cache["FirstName"]
Thanks,
Related
I am new to WCF, I am trying to create a WCF selfhost service with dynamic URL, which will be used to authentication user from client computer. this service will be installed in all client computers and web application should work if it finds this WCF service in client computer. Please Help.
First, you can implement self-hosted wcf,
https://www.c-sharpcorner.com/UploadFile/137605/self-hosting-in-wcf/
https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/self-host
and then dynamically switch the wcf web service reference url path through the configuration file.
How to make your Service-Reference proxy URL dynamic?
Dynamically switch WCF Web Service Reference URL path through config file
How Dynamically change URL in a WCF Custom Behavior
Created a Basic Azure Service Fabric , Stateful Service, using reliable service framework using .NET core.
Created a values controller with get operation returning string collection
created endpoint configuration in service manifest with protocol of http
Created DNS service name in the application manifest for the service
Created Azure service fabric Cluster from portal
Configured the nodes with ReverseProxy and Enable DNS
Configured the LB rules 8081,80,19080,19000
Have healthprobe at 19000,19080,8081
Published my azure fabric application from Visual studio, and I can open the fabric explorer, it shows my services are deployed correctly
but not able to access the service from outside of cluster
http://domain.eastus2.cloudapp.azure.com:19080/MyCalculatorApplication/AgeCalculatorService/api/values throws exception as {"Error":{"Code":"E_INVALIDARG","Message":"Invalid argument"}}
When you are trying to use the naming service of service fabric, first you should resolve the endpoint using this url:
http://domain.eastus2.cloudapp.azure.com:19080/Services/MyCalculatorApplication/AgeCalculatorService/$/ResolvePartition?api-version=3.0&PartitionKeyType=1&timeout=60
Then you can use one of the endpoints
I'm not sure that this is the correct endpoint.
Your url should be something like this:
http://domain.eastus2.cloudapp.azure.com:SERVICEPORT/api/values
I have old school web service and it is configured to impersonate the caller. Works with no problem. Now I am thinking about adding another more higher level ASP.NET (non-wcf) web service which would be calling the original web service.
The question is - will the client identity flow across two hops as in client (1)-> new web service (2)-> old web service) or there will be issues?
I believe unless the new ASP.NET web service impersonates the client, the identity will not flow to the second web service. If there is no impersonation then windows identity of the worker process will be sent to the old service. With impersonation, new service code will run under same user as that of client and then using DefaultCredentials, you can call the old web service.
I've two separated projects being one of them a Windows Service having another one has a reference.
I want my Service to call a method from the referenced project, something like this:
protected override void OnStart(string[] args) {
MessageSystem msg_system = new MessageSystem();
IQueryable<MensagemGrupo> mensagens =
msg_system.GetScheduledMensagensGrupo();
foreach (var msg in mensagens) {
msg_system.ConfirmaEnvio(DateTime.Now, msg.id);
}
The code i'm invoking throw the Service:
public class MessageSystem {
private StorageModelDataContext db = new StorageModelDataContext();
public IQueryable<MensagemGrupo> GetScheduledMensagensGrupo() {
IQueryable<MensagemGrupo> mensagens = db.GetMensagensGrupoAgendadas();
return mensagens;
}
}
I'm getting a System.NullReferenceException starting at db.GetMensagensGrupoAgendadas(). Could it be because db is in a remote server?
Can i call methods this way from the service?
PS: The Service is LocalSystem. I've tried Network Service but i get "Error 5: Access Denied" while starting the service.
Do you want to call this via a web server, or do you just want to run the same code that's in your ASP.NET MVC app within your Service?
If it's the latter and you're calling a remote server that uses integrated authentication, your service has to run as a user that is valid on the remote server (that user will need 'logon as a service' rights to be able to run the service).
Do you want to call this via a web server, or do you just want to run the same code that's in your ASP.NET MVC app within your Service?
If it's the latter and you're calling a remote server that uses integrated authentication, your service has to run as a user that is valid on the remote server (that user will need 'logon as a service' rights to be able to run the service).
If you want to use it as a webservice (ie. the ASP.NET MVC code runs on a server and you make requests to it from your service), you should add a web reference to the appropriate URL your ASP.NET MVC application exposes, not a normal project reference to the project. See Scott's post on mixing ASP.NET WebForms with ASP.NET MVC and look at the example with the ASMX service for more details on creating the web service, then add a web reference (or service reference) to that ASMX from your service project.
[edited to clarify the web service option after seeing jvalente's comment]
I solved that problem using a Web Service in the ASP.NET MVC app that is executed thought the windows service.
I have some knowledge about web services and how to add web preferences in the project.
In my project there is a same web services will run on more than two server.
All web services are same just their servers are different.
So is there a way to add web services dynamically? and i can call web services from the server which user specify if there is no web services available then it will return false.
I need to call server dynamically as user specify server name.
Use web service proxy's Url property to set the new url dynamically. Store URL of the web service in your application's parameter table / config file. At runtime always get the web service's Url from that parameter and set it to your web service's Url as destination.
Ok, I'll give an example how to use it. For example let's say we have to add this web service to your project :
http://server1/service1/service.asmx
And then we specify MyService as proxy name to your web service. Then while we use this web service set the Url property like that to specify your proxy's destination :
MyService myService = new MyService();
myService.Url = "http://server2/service1/service.asmx";
myService.GetOrders(customerNo);