WCF Service Reference issue on production in console application - wcf

I have 1 c# Console Application project, which has Program.cs (that contains main method), the main method simple calls a web service method and displays the string on the console.
The service reference is added in the project by right clicking it and adding service reference it to it.
when the console application is executed in debug mode from visual studio, it works as expected.
when the console application is executed from a .exe found in /bin/debug, it works as expected.
so far so good.
PROBLEM:
when the project is copied over to the system (you can call it a production environment), where this .exe will actually be executed, it fails at the exact line where i create the service proxy object. the line in Program.cs is:
ProjectName.ServiceReference.ServiceClient service = new ProjectName.ServiceReference.ServiceClient();
I know it fails here, because i have Console.Writeline("some line"); before and after the above line. I can see the Console.Writeline that is before the proxy line, and soon after that it crashes ...
I think this is because the reference paths that are referencing the service, is there any thing i can do to change the paths, or confirm that it is the path issue as suspected ...??
any idea whats going wrong ..???

Check this link: http://blog.davidsandor.com/post/Workaround-The-configuration-for-the-servicee280a6Unrecognized-element-e28098extendedProtectionPolicye28099.aspx
The configuration for the service reference could not be updated due
to the following issue: Unrecognized element
‘extendedProtectionPolicy’. (App.config / Web.config)
There does not seem to be a really clear reason why this is happening
however it seems to be related to Windows 7. I am not sure if the
.NET framework that ships with Win7 has some different setting or
template for the WCF configuration policy files but it seems to be the
culprit. Maybe the machine.config files are different on Win 7 and
the WCF configuration tools use the machine.config as some sort of
policy template.
The fix is annoying (because every time you build your solution on
Windows 7 and then rebuild on Vista you have to redo this).
Remove the line:
<extendedProtectionPolicy policyEnforcement="Never" />
from both your App/Web.config file on the client and on the WCF
server’s Web.config file.

Related

Publish a WCFService doesn't work; Debugging-mode works

I want to start an default webservice-project, where I can send data over a service. When I go to debug the API through VS then everything works fine, but not when I try to use it over IIS.
I created an WcfServiceLibrary-Project in Visual Studio 2017. I then right-clicked on the project (in the solution explorer) and then published it to a folder A.
I also didn't do anything special at IIS (all the things are still on localhost.): I activated the default windows-feature "IIS". (The default web site got also stopped). Then I added there a site with an random name and the path to the folder A. The service got started.
My access trial was to find anything through Visual Studios "connected services".
Has anyone an idea?
At first, please use the WCF service application project template,
or the Appconfig file would not be kicked in. library project needs the additional configuration in the hosting environment, and the Appconfig file could not recognized. We have to move the configuration code into the configuration file recognized by your hosting environment.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/deploying-a-wcf-library-project
Secondly, for hosting the WCF service in IIS, we should enable the below windows feature.
Feel free to let me know if the problem still exists.

Updating Service reference WCF in VS2010 SP1 (mvc3 project) TFS -- Causes other developer failing to compile

On my local machine, I consume a WCF service via the Service References. I can add to the other WCF project and check in to TFS , run the service, Go to my main project and Click on Update Service Reference, and my web.config is fine whether change is needed or not. Rebuild is fine.
However, on another developer's machine, they make a change to the WCF Service run it, and go to main project and Update Service Reference, and sometimes the web.config get trampled, it doesn't show the Url to the wcf service etc... Thus compiling project causes a issue where it cannot find the namespace for the service reference.
Then if I get latest and checkin and tell a developer to get latest, their web.config will update, but they still increasingly have a problem with the namespace for the service reference does not exist. It is running, the update to the service works. The Url in the browser shows the endpoints.... but vs 2010 sp1 has repository files that cannot find the service reference for some reason. "Are you missing an assembly reference?" Any ideas??
If in the svcutil dialog, the option to use shared assemblies is turned on, and if any signed assemblies are not an exact match, the checked in version will fail on the other machine.
You need to make sure the assemblies used have the same public key token.

Problem with type of service in ServiceHost directive in wcf service

I am developing a simple wcf service for test. When I test this service with my local IIS 7.5, then it works properly. But when I host it in web IIS, I receive this error:
The type 'WcfServiceLibrary1.Service1',
provided as the Service attribute
value in the ServiceHost directive, or
provided in the configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations
could not be found.
And my ServiceHost is:
<%# ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary1.Service1" %>
Please help me resolve this problem
Because I couldn't find this suggested in any of the questions I looked through for this, adding my case here:
I had this problem when I manually changed the namespace in the file MyService.svc.cs, and did not change the Service name in the corresponding file MyService.svc - turned out that it needed to be Service="namespace.classname".
Try using the assembly qualified type name.
This is [Fully Qualified Type Name], [Assembly]
Where [Fully Qualified Type Name] is, in the most common cases YourNamespace.YourType
And [Assembly] is, in the most common cases YourAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
It gets more complicated than this (generic types, nested types etc) - but unlikely to be so in your case.
If your application is using the default build options, then I'm going to hazard a guess that the directive should be something like this:
<%# ServiceHost Language="C#" Debug="true"
Service="WcfServiceLibrary1.Service1,
WcfServiceLibrary1,
Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null" %>
Although you'll probably want to get rid of the newlines there.
Also, make sure your dll has actually been deployed
I had the same issue only when publishing my service but it worked locally.
It turned out to be that the service was referencing a DLL that wasn't being deployed. It's a super special case because it was a system dll (System.Web.Helpers) and thus the project didn't even have a reference to it and thus the "Copy Local" wasn't set to true.
IIS defaults to expecting to see the svc file in the virtual directory, and the binaries inside a bin folder (as marc_s commented).
However, the default build configuration for WCF Library projects is to build inside a bin/Debug folder (or bin/Release). You can change the Output Path to 'bin/' on the project properties Build tab.
Changing this resolved this error for me today.
I had this same problem after I deployed a working service to a new location (new site) in IIS. In inetmgr under the Default Website tree, I hadn't right-clicked the new site and selected Convert to Application - all working now!
Finally my problem solved.
I removed the service directory in my host and created a new virtual directory in the host space. Then I copied my service in new directory where I created it.
Now I can browse the .svc file for service and my client will consume the service.
I don't understand why this problem occurred! I am a little confused!
The answer marked as answer is very difficult to understand. In fact, although it led me to solve my similar problem, I don't know if that's because I accurately understand what the writer was meaning.
I was finding if I pointed an IIS application on my development machine to the actual project directory in which resides the web.config, MyService.svc, and bin folders necessary for the WCF Service Application it just wouldn't work, and was throwing this error. This is despite quadruple checking every setting and ensuring that things were equivalent to other simple, working WCF Applications.
Ultimately, I solved the problem by publishing to a different directory rather than depending on the project files and directory themselves.
Perhaps it was because the files were open in Visual Studio as I was trying to run the WCF application through IIS? I don't know, but the Visual Studio provided localhost:59871/... was working. I don't know if that instance is using the project files or a temporary published version.
Check whether namespace and class written in "Service" of "SeviceHost" is correct .It should be Service="namespace.classname" .
Another reason for this issue is often when a wcf service is moved from one directory to another, and the svc file has not been updated... easiest solution is to double check your .svc file and make sure the service definition is defined correctly.
As I can't up vote #jeromeyers answer at the moment, I want to add that this is the solution that I found for this issue.
Someone had copied and pasted a svc file and associated contract and code files to a new project, but they had not updated the namespaces and class names everywhere. Very frustrating tracking this down as it started with this error :
" name was started with an invalid character. Error processing resource 'file:///C:/...
<% #ServiceHost "
when trying to right click on the .svc file and doing "View in browser".
Even though this is slightly different than the question (not web iis): I got here through search because I was getting this error trying to Debug my service -- if you have multiple services inside a single solution, this error will occur if the solution in question is not built yet, and therefore the DLL not created when you try to access it. So to anyone out there make sure if running locally that the entire solution is built!
had this problem running a test project that was embedded in my solution.
I had to view in browser, then copy that link to a new service reference (delete the old one) then paste it in rather than using the discover utility button in the service reference.
Strange as well, after looking and trying others suggestions, i was still getting the error saying the:
The type ', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Sure we all get large project with a lot of DLLs. Turned out some of the older components in my solution were targeting .Net 4.5, and newer dll were build with 4.5.1. When the 4.5 dlls referenced the 4.5.1 dlls .... Not sure why i was the happy little guinea pig to be the first on my team to find this. While the fix was obvious and easy enough, just all the dlls to target the same .Net runtime.
Just wish Visual Studio would notice DLLs within the same solution should all target the same .Net runtime and generate a warning/error when building especially with we have a solution and a project reference and the runtimes don't match...
Be sure your compiled dlls are moved to service(IIS directory)
directory.
For example, sometimes Jenkins doesn't move them automatically.
I had the same issue when i uploaded my working localhost service to a new location on host.
I create a new Virtual Directory and published my Service to it via Visual Studio(FTP). Problem Solved.
It happend the same to me and the solution was creating a forder named "bin" and place the dll inside of it. Then, refresh the website on IIS and that's all
I had this problem too, and what did the magic for me was to restart the IIS.
This is a very weird error.
First time hosting WCF Service Application, in IIS ?
Many have solved their problems one way or the other. However if everything is your solution is correct and your error is about host your app in IIS, then ensure your physical path in IIS when you add your website is pointed to the "bin" directory of your solution as seen below in the screen shots.
Please look at https://msdn.microsoft.com/en-us/library/ms733766(v=vs.100).aspx
You need to do 2 things to be able to Host the Service on IIS, or even on Visual Studio's itergrated IIS_EXPRESS.
1) Update the Web.Config to include ServiceActivations
change:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
to
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<serviceActivations>
<add service="API.Service1" relativeAddress="Service1.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
2) You need to create a directory called App_Code in the root directory.
You now need to move the Service (ex: Service1.svc) from the root directory into the App_Code directory.
So you will have App_Code\Service1.svc
If you browse the Service
http://localhost:63309/Service1.svc it should work.

Debug WCF service hosted in local IIS not working

I have one solution WCFSampleSolution and it has all my projects - Web Service, Client and Website. The structure is something like:
WCFSampleSolution
C:\WCFSample\Website
WCFService
WCFWebClient
I created WCFService project for my services. It contains IService1.cs and Service1.cs. Then I hosted the service in IIS. I did this by creating a website and adding .svc and web.config files to the website project. Then published it in IIS. When I run http:\MyMachineName\Website\Service.svc, it shows the service description. Then I create the web client that calls the webservice. I used the service reference to add the service. It calls a method of Service1. It works fine. But I amnot able to debug this program/setup. I verified the config files in WCFWebClient project and Website project and they have proper debug settings.
<compilation debug="true">
I put break points but control never goes to my seb service. I also tried attach process, but it also doesn't work. But I was able to debug one of my other WCF projects. The setup was little different. In that project I copied the .svc file and config in my web client and the debug works fine.
Please HELP!!
You are hosting your service on IIS so I am sure you must be attaching to w3wp.exe process. While trying to attach if VS built in web server is starting, then attach to that process as well.
What I find particularly easy is having two instances of visual studio open (especially if you use NUnit or doing anything to test out code). One will attach NUnit or whatever you wish, and the other will attach the w3wp.exe process. The easiest way is to:
1) Put a break point in the 1st instance of visual studio of the code right before it will hit the WCF service hosted on your machine.
2) Once the code stops at your breakpoint, set breakpoints in the 2nd instance of visual studio where you want to break then attach the w3wp.exe process.
3) Once you continue, the breakpoint on the service code should be hit.
It is sometimes easier to find the process id as well when attaching w3wp.exe. Using IIS, you can go to "Worker Process" and find the process id to attach for your Application Pool Name.
#user465876 - another approach that is less of a hassle can be found here: WCF can no longer step into a service that's locally hosted -- why not?

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.