Referencing a Published WCF Service - wcf

I have followed "Walkthrough: Creating and Accessing WCF Services" from http://msdn.microsoft.com/en-us/library/bb386386.aspx to create a WCF Service Library. I tested it in WCF Test Client. Then in another desktop application (let's call it A) that eventually I would like to use this WCF I added the Service Reference that WCF Test Client gives
http://localhost:8733/...
and that worked too.
Now, I am in the process of publishing and using the published version's service reference. Here is what I did, I published the WCF Service Library by
right-clicking the solution
Choosing Publish
clicking ...
Choosing File System and typing
\mywebaddress.example.com\wwwroot\myWCFService
Looks like the publish is successful, because by navigating to
\\mywebaddress.example.com\wwwroot\myWCFService
in a file browser, I see that Web.config, .svc and bin folder are created.
Now, I am trying to refer to this published version from my desktop application A. I am not certain what options I'm supposed to choose
Here is what I have tried:
Choose Add Service Reference in the desktop application A,
I tried
\mywebaddress.example.com\wwwroot\myWCFService
in the Address field of Add Service Reference, Pressed Go and received the error An error (Details) occurred while attempting to find services at
\\mywebaddress.example.com\wwwroot\myWCFService.
When clicking on Details, I get There was an error downloading
\\mywebaddress.example.com\wwwroot\myWCFService
Access to the path
\\mywebaddress.example.com\wwwroot\myWCFService
is denied.
If the service is defined in the current solution, try building the solution and adding the service reference again.
Alternatively, I tried Advanced option from Add Service Reference and from there Add Web Reference... and in the URL field typed
http://www.example.com/myWCFService/
then when pressing the arrow button I get 401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied. and in the Web services found at this URL: Value cannot be null. Parameter name: discoveryError & mexError.
Th latter error was when in the IIS setting I had Anonymous Authentication Disabled. After enabling Anonymous Authentication the error becomes:
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
Web services found at this URL: There was an error downloading
http://www.example.com/wcfservice/_vti_bin/ListData.svc/$metadata
The request failed with HTTP status 404: Not Found.

When I just now published a WCF Service Library project with Visual Studio 2013, I was offered the options for file system, Local IIS, and FTP Site. When I choose "Local IIS", it shows me both IIS Express and my local full IIS.
I just published to IIS by selecting "Default Web Site" and clicking the "Create Web Application" button in the tooolbar. I named the application, clicked "Open", then clicked "Publish" on the main publish dialog.
This published a bin folder with the service DLL and other libraries it needed, a web.config, and a .svc file. I was able to browse to the .svc file with no problem. I was even able to add it as a service reference to another project.
If you are always going to host your services in IIS, and if you don't need to keep a clean separation of layers (perhaps you're only writing a few, simple services), then I recommend you use the "WCF Service Application" template instead. This creates a Web project in which to host the services, as well as the .svc and .cs files necessary for the services themselves. That's more like the only option that was available for ASMX web services.

Related

NetCore API Impersonate

I have a Web and an API NetCore Application running in a machine that I have access by VPN.
There, in IIS, I've configured both applications in IIS: The Web and the API. They are running well.
At the API, I've tryied to open the file from a network path:
\10.50.20.24\g$\Buffer\821003\003\22\34\821003003223428.WAV
In my code, when I try to verify if the file exists, using System.IO.File, to after move it, I received a message saying that the file doesn't exists.
"file was not found"
But the file exists, and the file is there when I try to access it from Windows Explorer.
In the IIS, I've configured the same user to run the application, in the Identity of the application pool.
I've tried lots of things to try to access the file, unsuccessfully.
Do you think this is related to Impersonation? How could I implement Impersonation in Asp.Net Core API 3.1 ?

.NET Standard: Microsoft WCF Web Service Reference Provider does not ask for credentials

In a c# console application, whenever I clicked Add > Service Reference and inserted a WCF URI, and I would be prompted to type my credentials:
When I try to do the same thing now in a .NET Standard solution (and after upgrading my Visual Studio to v15.5.6), I click Add > Connected Service > Microsoft WCF Web Service Reference Provider, I input the URI but I do not get the prompt for credentials, I simply get error 502 Bad Gateway!
Does anyone know how to get the Connected Service to ask for my credentials?
PS: I tried adding the username/password in plain text in the URI (using username:password# syntax) but still no luck.
As an alternative can you not use the browse button to point to the .wsdl file in the Local disk.
That way you are guaranteed your reference is pointing to the correct path.

Https WCF webservice giving Http 400 error while calling method from browser

I have created a wcf web service. When i run it for http it works fine and gives result in wcftestclient as well as browser.
But when i test for https by changing it fot https it gives result in wcftestclient but when i try to call method from url by passing parameters. i receive error.
HTTP 400 error
It’s not you, it’s this link (it appears to be broken).
I have changed configuration file for https. It is working in wcftestclient but not in browser. it gives wsdl file but error for method calling.
I call method as
https://my-pc/Service.svc/LogIn?a;a
Quick way is Goto project properties of your WCF Service Project in Visual studio, open Web tab/page and make sure IIS web server is selected and IIS Express not selected mention your web address like https://localhost/WcfService1 and if virtual directory is not created then Click on "Create Virtual Directory Button", visual studio will create with required SSL settings for you.
To verify open Internet Information Manager(inetmgr), select service virtual directory/website and verify binding in Actions pane on the right hand side.
It should have two browse links under Manage Application heading one for HTTP and one for HTTPS.
Hope this helps.

Basic WCF service gets "Invalid application path" on Test Settings

Caveats: It's been six years since I deployed a few web services and my knowledge of IIS is slim.
Background: I'm trying to host a WCF 4.0 service under IIS on my local box (Win7 64-bit) but keep getting "Invalid application path" when attempting to Test Connection. So I've gone vanilla and
created and started a new WCF Application (via the .NET template) (so responds under Cassini);
added a new application under the Default Web Site;
assinged it to the DefaultAppPool;
set the path to the folder where my .svc file resides; and
verified that the DefaultAppPool is targeting the 4.0 framework
Also, when I test the default web site settings pass-through authentication succeeds but an Authorization warning indicates "Cannot verify access to path (C:\inetpub\wwwroot).
Problem: When I pull up the apps basic settings and click "Test Settings..." I get an error "There was an error while performing this operation. Details: Invalid application path"
Does anyone have suggestions as to how to get the settings to check out correctly?
Thanks.

How to add a service reference to a WCF client for a web service requiring client authentication certificate

Caution, WCF noobie alert
I need to create a WCF client to query a non-WCF web service.
The web service is not a WCF service. Additionally, the web service requires a client authentication certificate. Now, I have the certificate, and can create a non-WCF client that works perfectly; I was able to 'Add Web Reference' and a certificate dialog box opened up to allow me to select the appropriate certificate, then went on to create the web reference. Trying to create a WCF client via 'Add Service Reference' is another story, it just fails with a 403 Access Denied error.
I have the WSDL for the service, and have run svcutil.exe on it, but am not sure how to proceed from there.
Thanks for any help!
I'm assuming that the service you are using is performing client SSL authentication.
Since add service reference is failing, you can use svcutil to generate the client from the WSDL file that you have. I think the syntax would be something like:
svcutil *.wsdl /l:C# /out:Reference.cs /config /s /ct:System.Collections.Generic.List`1 /ser:Auto /tcv:Version35 /n:*,<NameOfYourNamespaceHere> /edb
This will generate a file, Reference.cs, that contains the proxy classes to the service (you can give this file whatever name you want). Add this file to your project. A config file, output.config, will also be generated. You can add this configuration to your application configuration instead of typing it all in by hand.
Now you can follow this MSDN article on using Transport Security with Certificate Authentication. You can skip down to the client section where it shows how to attach the certificate to the request in code as well as in configuration.
I know this is the old question and it has been already solved but I would like to mention that Add service reference also works for WSDL files stored on disk. Marc has also mentioned it. Add service reference dialog accepts:
URL to WSDL
URL to Metadata exchange endpoint
Service URL where /mex is added internally
Any file path to WSDL file
So if you have WSDL and all need XSD files you can use Add service reference as well. The only tricky part is that Add service reference dialog doesn't have Browse button and that is the reason why this functionality is not well known.
Stupid question (maybe): could you connect to the service endpoint, present it with your credentials stored in the certificate, and then download the WSDL (and possibly XSD) from there? Or could it be the entity offering this service would be able to actually send you these files (or make them available for download)?
Once you have the WSDL (and XSD) file on disk, it should be easy enough to create WCF client for that (using either svcutil.exe or Add Service Reference) based on those files, and then configure the appropriate security for it.
Just a thought.... (worth $0.02?)
Marc
OK, bit of a work-around here (and I've no idea what is going on technically): I noticed that when you add a Web Reference, the certificate you have chosen is cached and automatically used the next time you add the Web Reference (I noticed because I'd chosen the wrong certificate). This caching seems to work across Web Reference and Service Reference so:
Add a Web Reference to the endpoint, choosing the certificate you wish to use
Remove this Web Reference
Add a Service Reference to the same endpoint and Visual Studio will use the same certificate you chose for the Web Reference
Worked on Visual Studio Community 2019, v16.7.7