First, I created a WCF service (netTcpBinding) hosted by a server application and all work fine (tested with a client application).
Then, I imported the same service class in a prism module (IModule). In the module, I create an instance of the ServiceHost by using the service class type:
public ServiceHost Host = new ServiceHost(typeof(MyService));
In the initialization step, I open the connection:
try
{
host.Open();
}
catch (Exception ex)
{
log.Error(ex, "SAP service starting is failed.");
throw;
}
When I attempt to connect with a client application to the WCF service, no error is occurred: Address, binding and contract are found in the configuration file, the instance of the ServiceHost is correctly created and gets the status "opened", the socket connection is opened. From the client application, I am able to perform a call to a method of the service (no error occured to the socket opened by the server) but the service doesn't receive the call: a break point at the top of the called method is not hit during a debug session of the WCF service.
When I add a service behavior (httpGetUrl and httpGetEnabled to true) in the configuration file to get the WSDL information, the link does NOT occur any error but the page stays blank and its title keeps as information "Loading ..." (no WSDL generated).
If I move the service class and the creation of the service host to the prism executable project (.exe) which initializes the modules, the WCF service works fine !
By adding the diagnostic tools in the configuration file of the service () and by calling the "test" method, I can see the last logs:
Any idea ?
Can we create a service host in a library project working like a prism module ? Is there any contraindications ?
I've found ! But nothing linked to prism or unity.
The application set an notify icon in the right bottom of the screen. This notify icon has a context menu to finish the application. The notify icon is associated to the thread of the application.
Later, I added TopShelf to start the service. It seems that the adding of the context menu occurs a problem. I have no exception but well the problem described above. The removing of the context menu solves the issue.
There is no contraindications to define a WCF service host in a prism module. That works perfectly.
Related
We have a WCF service hosted as nettcp mode and WCF client library, both services and client has been created using .net framework.
Now we are creating new application using Asp.net core 2.1, still here we need to consume the above created WCF Service using the same old WCF client Library.
Added this WCFClient library reference(.net framework) into our Asp.net core application. Here am using the below proxy constructor to pass my end point details.
public LoggingServiceProxy(Binding binding, EndpointAddress remoteAddress)
: base(binding, remoteAddress)
new LoggingServiceProxy(new EndpointAddress("net.tcp://localhost:9100/LoggingService/Tcp"), new NetTcpBinding(SecurityMode.None));
After adding System.ServiceModel.NetTcp and System.ServiceModel.Primitives NUGET references, resolved all other errors. But code thread aborted abruptly when it executes the proxy code
((ICommunicationObject)this.channel).Open();
No more information, debug message available after this point. No exception raised.So we have no clue on what is it?
Note: When I stop my service to test, I clearly get exception "EndPointNotFound".
Expected behaviour is to able to consume the service from Asp.net Core application -> WCF Client Library(.net framework) -> WCF Service nettcp (.net framework)
After did more dig into the auto generated proxy code, found that this issue is happening in the event of InnerChannel_Opened() and InnerChannel_Closed()
Above event got the following line of code "lock (this.channelLock)" which causes the issue. No exception raised. simply thread aborted/exited. When comment it out these events, it works fine, but am not too sure whether it is ok to comment these auto generated code.
lock (this.channelLock)
{
if (this.IsDisposed)
{
throw new InvalidOperationException("Cannot use disposed object.");
}
if (this.Opened != null)
{
this.Opened(sender, e);
}
}
I'm approaching to WCF Service, starting with the tutorial provided by Microsoft. I created a very simple WCF Service (CalculatorService) and I've some doubts about the EndpointAddress of this service.
When I create the WCF Host, I set the Endpoint like this:
Uri baseAddress = new Uri("http://localhost:8000/GettingStarted/");
// Step 2 Create a ServiceHost instance
ServiceHost selfHost = new ServiceHost(typeof(Service1), baseAddress);
// Step 3 Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(), "CalculatorService");
Everything works if I debug the entire solution, but, if I launch the WCFHost executing its .exe file, launching also the application of the Client gives me the following exception:
System.ServiceModel.EndpointNotFoundException: No endpoint listening in http://localhost:8732/Design_Time_Address/WcfServiceLibrary/Service1/.
The fact is that if I try to open a browser and search the address http://localhost:8000/GettingStarted/, I get correctly the page of the Service. I suppose that the Service is hosted at one address and the Client tries to access to it via a different one.
Could anyone help me to solve this issue?
If you have, in the client code, hard coded this address http://localhost:8732, then change it there. But your client is probably (you didn't put that info unfortunately in your question) automatically generated. In that case client config is in App.config file(if we are talking about your solution), and in config file of the .exe file when you build your project. You should look into your [ClientApplicationName].exe.config file and update the endpoint address to port 8000.
How can i add wcf service at runtime in my winform UI.
I created a wcf service which return running processes of hosted machine. I want to add the hosted machine service in my winform application.
You need to change endpoints dynamically at runtime, so You need WCF Discovery.
Structure :
WCF Consumer(s) <---> WCF Discovery Service <---> WCF Service(s)
Implementation :
How to: Implement a Discovery Proxy
How to: Implement a Discoverable Service that Registers with the Discovery Proxy
How to: Implement a Client Application that Uses the Discovery Proxy to Find a Service
Topology :
Start Discovery Service [ Structure BackBone ]
Start Service(s) [ Every Service will ANNOUNCE its startup to the Discovery Service ]
Start Client(s) [ Every Client will DISCOVER ( FIND & RESOLVE ) Services' endpoints from the Discovery Service ]
Notes :
Discovery process uses UDP ( Check your Firewall, It can block connections )
Services MUST announce their startup, thus Self-Hosted services is OK, but IIS-Hosted 5/6 ones is NOT because they started automatically when 1st invoke happends !
Solving IIS-Hosted 5/6 Issue :
By Extending Hosting Using ServiceHostFactory
So that you can start your IIS-Hosted 5/6 services manually without being invoked for the first time
You can also use WCF Routing Service.
BROTHER TIP :
Don't go far for a Serverless ( No-BackBone, No-BootleNeck, Fully-Distributed, .. etc ) ideal topology, this'll blowup your head and got you crazy :D
For a beginner, I suggest you this tutorial [ WCF Tutorials ]
not sure what you are trying to do here. But you need to know two things to call the WCF service 1) Service Contract 2) End Point. Now there is no escaping from Service Contract as you need to know what all operations you can consume. However, with WCF 4 there is a new feature called WCF discovery which helps you determine the end point dynamically i.e. at RunTime. Refer to following link http://msdn.microsoft.com/en-us/library/dd456791.aspx
If I understand you question properly you need some code that will add service in run-time without using any configuration in *.config file and *.svc files.
See that sample:
Uri baseAddress = new Uri("http://localhost:8080/hello");
// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress))
{
// Enable metadata publishing.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
// Open the ServiceHost to start listening for messages. Since
// no endpoints are explicitly configured, the runtime will create
// one endpoint per base address for each service contract implemented
// by the service.
host.Open();
Console.WriteLine("The service is ready at {0}", baseAddress);
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close the ServiceHost.
host.Close();
}
It creates self-hosted service in console app.
http://msdn.microsoft.com/en-us/library/ms731758.aspx
Is that what you asked?
I have a windows service that has it's name set by an app.config.
I set the name as follows:
The ServiceBase.SerivceName is set on the Service class constructor (I have removed the setting of the ServiceName in the Service.Designer):
ServiceName = ConfigurationManager.AppSettings.Get("ServiceName");
The ServiceInstaller sets the DisplayName and ServiceName like this:
ServiceInstaller.DisplayName = config.AppSettings.Settings["ServiceName"].Value;
ServiceInstaller.ServiceName = ServiceInstaller.DisplayName;
All works as expected, so the service is installed fine alongside a duplicate service.
They have different names and different locations.
The appear as seperate entries in the Services list.
But I can only start one service at a time. The error I get on trying to start the second service is the unhelpful:
The service is not responding to the control function.
There are 2 System Events that get logged when trying to run:
A timeout was reached (30000 milliseconds) while waiting for the Blah Service service to connect.
The Blah Service service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.
Any help gratefully received.
Thanks.
In the absence of sufficent info to offer an answer to the problem at hand, I suggest using http://topshelf-project.com/ - it makes installing, configuring and debugging windows services in .NET a breeze.
I am using VS2010 + C# + .Net 4.0 + IIS 7.0 + WCF. When I create a WCF client object instance in below code, I find "check point 1" is logged, but "check point 2" is not logged. But no exception is thrown (I catch exception in the whole block of code, and "check point 3" is not output).
Any ideas how to debug further to see issues in WCF client proxy creation? What are the normal issues in WCF client proxy creation (I think the creation just need to create a local memory object to represent the WCF client object instance, no need to really communicate to remote WCF service, so should not fail normally, please correct me if I am wrong)? Maybe some configuration errors?
BtW: the code below is in a WCF service (WCF server end, running/hosted in IIS 7.0) to call another remote WCF service.
try
{
MyLogger.Write("check point 1 " );
Foo.CustomerInfo ci = new Foo.CustomerInfo();
MyLogger.Write("check point 2");
}
catch (Exception ex)
{
MyLogger.Write("check point 3");
return;
}
thanks in advance,
George
Few ideas:
Try putting logging in Foo.CustomerInfo() constructor
Try using end to end tracing with Service Trace Viewer (usually in NETFX 4.0 Tools\SvcTraceViewer.exe).
Make sure you have you service return exception details in faults so client can "see" them (e.g. serviceDebug includeExceptionDetailInFaults="true")
If you autogenerated client proxy, you can still edit it and add logging in the partial class of client proxy