WCF Service behaves differently when installed - c#

I have written a WCF service which acts as a data access layer for my client applications.
The service loads and calls api from a managed assembly which I have referenced in my service project. A windows service is hosting my WCF service. Also I have implemented a wix installer to install my service. the communication is going to be only WCF-WCF
Now the problem is when I run the service from Visual studio then all the api's are working as expected but when I install my service then, api's don't throw exception but doesn't return expected result. To solve this problem I tried following things
1)Tried basicHttpBinding, wsHttpBinding and netTcpBinding
2)Changed the service log on setting as admin
Can someone point out the problem here? I tried lot of things suggested in different sites but nothing was helpful till now. Please let me know if you need more information.

Related

Consume and invoke Web Service that has implemented ws-security WSS (UsernameToken and docs.oasis-open.org) from net core

I am developing a software that, apart from having its own BackEnd, has a module that must be integrated with an external web service. The external web service is as follows: https://e-seida.sunat.gob.pe/ol-ad-itseida-ws/ReceptorService.htm?wsdl
In the project (.NET C#), it can be easily referenced and I can see all the contract and methods that the external web service has exposed. I can do the same thing from the SOAP UI when I test successfully hitting the web service.
As you can see in the image, when you hit the web service, you have communication and a response from the SOAP UI. Now this does not happen in my project because although it is true the web service could be referenced, but until now I am still looking for the way or way to send the security data (UsernameToken) to the web service, honestly it is somewhat frustrating because I've been having this same problem for several days now and I can't give you a solution and researching I have found some possible solutions and none of them have really helped me.
I understand that the Header of this web service contains WS-Security type security, which is basically an open standard approved by OASIS to provide transport layer security (through SSL/TLS from HTTP).
I have also investigated some forums where they indicate that creating the following interfaces/classes (MessageHeader, IClientMessageInspector, IEndpointBehavior) but implementing that does not solve it either.
What can I try to resolve this?

The remote server returned an unexpected response: (405) Method Not Allowed when .NET 4.7.2 WCF service is called from a .NET Core 3.1 REST API

I have a WCF Service written for .NET Framework 4.7.2 at http://wcfservice.mydomain.com/service.svc
I also have a REST API written for .NET Core 3.1 at http://api.mydomain.com/
REST API has methods which act as transparent proxies which call WCF Service endpoints to fetch data. I have created the ServiceReference.cs in the REST API project via svcutil.
When I run the WCF Service both on Visual Studio 2019 and remote server IIS it works OK. No problems.
When I run these two projects on my local PC everything still seems OK. REST API works perfectly, calls data from WCF service and return response correctly. But when I move these two projects to the remote server IIS when I call the REST API it returns "The remote server returned an unexpected response: (405) Method Not Allowed" error.
Another strange thing is that for another project I use the same approach for a different REST API which works as a proxy to another WCF service hosted on the same remote server IIS, there is absolutely no problem and it works fine.
I have made some research and found no exact match for my case. Nobody faced this error while calling the WCF Service from a REST API. For the rest people mainly suggest two things : "Modification on Web.Config file" or "Adding WCF Activation".
First of all since I am using auto-generated code by svcutil I am not using a Web.config file which hold Service parameters and not sure to modify where and how.
Secondly, When I check the IIS I see that "HTTP activation" is already enabled under "WCF services" and I can not add "WCF HTTP Activation" under ".NET Framework 3.5". I face an error when I try to so.
Also I don't think these might be the solution because other projects on the IIS work well. I also checked application logs and Event Viewer logs but there is nothing helpful there.
I really appreciate a help on this issue.
Thanks in advance.

Get the version of Service hosted in IIS

We are hosting a WCF service in IIS. For tracking purposes we need to know the version of the service that's being hosted in IIS.
This service is part of an suite of services so we implemented all common functionality (Like the mentioned tracking service in a common library)
When trying to get the Assembly version using normal calls
Assembly.GetExecutingAssembly()
Assembly.GetExecutingAssembly(): get the version of the common Library
Assembly.GetEntryAssembly(): null
Assembly.GetCallingAssembly(): get the version of the common library
I also tried getting the call stack and getting the last one (got the IIS version).
Does anyone know how to programmatically get the version of the WCF service that is hosted in IIS?
I am assuming that you need to get the WCF service's version from within common library dll that is referenced by the WCF service at runtime. If not, I don't understand why you would get the common library assembly by running Assembly.GetExecutingAssembly().
If that is the case, then you want to find the assembly containing the Application object that IIS is running. By using the standard reflection methods on that root Application object, you should get a reference back to the dll that IIS is executing, which should be the WCF service.
Documentation for Application class:
http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
This looks like a promising way to get it:
http://msdn.microsoft.com/en-us/library/system.windows.application.current(v=vs.110).aspx
When talking about versions of WCF services, more likely you will realize you want versioning of Web services, rather than assembly version, though you mix both in your question.
The assembly version is of implementation details, and there are no legitimate case that you need to expose such implementation details through either Web services or IIS. IIS itself is of deployment detail, and has nothing to do with versioning of Web services.
System.Windows.Application is of WPF, has nothing to do with WCF or Web service.
When you learned programming, probably you had learned the once an interface is published, you should never alter it, though you could change implementation or introduce new versions of the interface. a Web service is basically an API or interface through http binding, and the description language is typically WSDL for SOAP base Web service.
In a nutshell, versioning of Web service is done through Xml namespace, and in .NET, you could have a mapping between XML namespace and CLR namespace. During deployment, you could have multiple versions of the same service being hosted in the host, so legacy clients could consume the legacy services, and new clients could consume the new versions. So you will have seamless transition strategy.
There's no direct link between assembly versions and service versions, and you should not expose assembly versions, since the clients say PHP or Java clients do not know what assembly version is.
For more details of starting points, here are a few good links if you google "Web service versioning":
http://www.ibm.com/developerworks/webservices/library/ws-version/
http://www.oracle.com/technetwork/articles/web-services-versioning-094384.html
http://msdn.microsoft.com/en-us/library/ms731060(v=vs.110).aspx

Confusion about WCF Class library and WCF application hosting

I have a web site and would like to expose certain functionalities using WCF.
Before deciding which type of WCF project I need to use I wanted to compare the differences between WCF Class library and WCF application. I know this question has been asked many times and answered many times and the answers are usually about different hosting options each one offers but I wanted to try and see the differences, so this is what I tried:
Step 1 - In a same solution, I have created a WCF Service library project and created Client console app project, set the console app as a startup project, referenced the service library project from the client project
and in the client console app I could instantiate the service and can consume the service methods. I didn't even add a service reference to the client project.
Step 2 - In a same solution, I have created a WCF Service application project and created Client console app project, set the console app as a startup project, referenced the service application project from the client project
and in the client console app I could instantiate the service and can consume the service methods. I didn't even add a service reference to the client project.
On both steps after compiling the solutions I was able to copy the client app's exe and the service dll's to a different location and still be able to run the clients.
Based on this little excercie I am confused about the hosting part. It seems wether I use WCF Class library or WCF application type I get the same result.
This is just like using multiple projects in a solution, you reference one from another and use the methods, there must be something I am missing which highlights the differences between the two and highlights the benefits of using WCF, also in the past I remember I had to add a service reference to the clients apps in order to consume the service, why is this not the case here?
Thanks
1) Running a wcf service application allows you to provide communication into a single application, where you have a single instance of a thing you want to provide access to. Maybe this is a game, or a chat room without an external state engine or datastore. This is useful for providing diagnostic information about an application you might have written for example. I used this to provide external control for an industrial robot that I wanted to provide remote control access for.
That is to say, that you write an application, it has a function. You want to expose part of that functionality to remote applications. You do this by adding a WCF endpoint to your existing application, so your application itself is controlling the WCF hosting elements, lifecycle of the endpoint etc.
2) Running a WCF Service is for when you've got an external data store, or your service is stateless. A translation service, lookup service and web page requests fall into this category.
With a service class, you're saying here is this service, this thing that provides a function. It isn't tied to the lifecycle of another application or process and is typically hosted by IIS. IIS manages when the class is loaded and run based on the requests that come into it. These services have no internal persistence and rely on an external datastore, or are, by nature, stateless (think of a postcode lookup, or a calculator service)
It sounds like you're actually adding the projects as references, rather than connecting to them as services. That is to say, that the consuming application is actually loading the service as an assembly (in the same application/ memory space) rather than as a separate application/ service that your application then uses WCF to communicate with.
The WCF Service Application template can be used to create WCF services with a hosting website created within the project
The WCF Service Library template can be used to create WCF services that are hosted by the WCF Service Host, and these can be tested using the WCF service Test Client.
the biggest advantage of using a standalone library (apart from decoupling the logic) is that you can easily migrate your service, i.e. host it in another application or another type of application. E.g., let's say you're hosting your service using IIS - you can easily move your service to a standalone application, etc.

Why Host WCF Service in Worker Role

In the process of building my first AZURE based application using WCF services I have stumbled across a number of examples where people show how one can host a WCF Service inside a Worker Role.
Such as in these articles:
http://www.codeproject.com/Articles/188464/Host-WCF-Services-in-an-Azure-Worker-Role
http://code.msdn.microsoft.com/windowsazure/CSAzureWCFServices-20c7d9c5
Very simple question, can someone please explain what use case would require hosting a WCF service in a worker role? What are the motivation/advantages of doing this?
Hosting a WCF service inside of a WebRole implies that it is hosted within IIS. Some folks prefer to not have the footprint of IIS mess with their ServiceHost and host the service directly. They have more control over how the communication with their service is done without IIS in the middle.
Also, when shrink-wrapping the packaged solution for customers, it is simpler to create an installer package without trying to rely on IIS infrastructure that customers may or may not have properly deployed/configured.
HTH

Categories

Resources