wcf Extract wsdl from WCF Service with Flattened WSDL - wcf

I have a wcf web service and I need to provide the client with the wsdl files.
Previously I used svcutil on the .dll and everything was fine.
However, recently I implemented the factory to Flaten the wsdl file (re: http://wcfextras.codeplex.com/).
My questions is this: Is there anyway of either using svcutil on the .svc to extract the Flattened .WSDL files or maybe somehow hit up the web service when it is running in the local webdev server to retrieve the .WSDL files?
As far as I'm aware, if I was to navigate to my local web dev server (http://localhost:2916/Service.svc?wsdl) and if i was to view source and saved that as .wsdl that this is wrong and would not provide all the relevant information.
note: See below for how the Factory is used in the .svc file....
<% #ServiceHost Factory="CompanyName.ServiceModel.Extensions.Description.FlatWsdlServiceHostFactory" language=c# Service="CompanyName.WebServices.Service"%>
Thanks,
Steven

Yes, you should still be able to use svcutil to extract the WSDL from your service, even if you have an extension installed that will flatten the WSDL.
To download the metadata document(s) from your running service, use this command:
svcutil /t:metadata http://service/metadataEndpoint
You need to point your URL to the metadata endpoint defined in your config, e.g. the endpoint that's defined to use "mexHttpBinding" or "mexTcpBinding" and the "IMetadataExchange" contract.
If you don't have any metadata exchange endpoints defined, you won't be able to retrieve that information, obviously.

Related

How can I use SimpleType in a WSDL data contract?

I use a wsdl file to generate web service with the help of svcutil but it generates class instead of simple int or string parameter for the service contract.
What I did:
I created a WCF Service Application
I created a Console Application then added the service reference to the project
I used svcutil.exeto generate service from thy wsdl and xsd files in console project
Why does it do that and how I can rewrite the wsdl to solve this problem, please?
Most likely you used /messageContract switch in svcutil.
If you added service via service reference, then right click on service->configure service reference and uncheck Always generate message contracts

Exposing WCF metadata on a SiteMinder protected site

This might be a really stupid question, but I've been unable to figure out a solution.
I have a WCF service hosted on a site that uses SiteMinder authentication. The authentication relies on a cookie in the client request.The problem is that when I try to generate a proxy class using svcutil, the operation fails because when svcutill tries to get the metadata, it obviously doesn't add the SiteMinder cookie to its request.I was therefore wondering if there was a simple way to generate the WCF service proxy class programatically.
If you have access to the compiled service DLL file, you can use the SvcUtil command line utility to generate the WSDL and associated XSDs for the data contracts. The main wrinkle with this approach is you'll need to add the name of the XSD file generated by SvcUtil in each xsd:import element in the schemaLocation attribute value.
Below are samples of modified xsd:import elements. For the "http://tempuri.org/" namespace, I added the schemaLocation attribute with the value of "tempuri.org.xsd" to let the Add Service Reference process know to look for that file in the same folder as the WSDL file. If your WSDL uses wsdl:import instead, add a location attribute instead of a schemaLocation attribute. This related question and answer should give a good start.
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import namespace="http://tempuri.org/" schemaLocation="tempuri.org.xsd" />
<xsd:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" schemaLocation="schemas.microsoft.com.2003.10.Serialization.xsd" />
</xsd:schema>
</wsdl:types>
EDIT:
Generating the client code using the compiled service DLL requires a two step process. SvcUtil needs the service WSDL to generate the client. It cannot directly use the compiled DLL.
First generate the WSDL using the DLL that contains the ServiceContract. I think you can use the service implementation file if the service contract DLL is also in the same folder.
cd "\Path\To\Your\Service\DLLs"
svcutil YourService.DLL
This will create several files depending on your service structure. There'll be one .WSDL file and several .XSD files. Edit these files as shown above.
Lastly, either use the Visual Studio Add Service Reference dialog to select the edited .WSDL file (just enter the full path and file name) to generate the client code or use SvcUtil as follows:
svcutil *.wsdl *.xsd /language:C#

How to get the original service from a wsdl file

i have a wsdl file, now i need to get the original wcf service. and after that i want to use(consume) that service in my web project.
please tell me is this possible? and how?
The WSDL contains only the definitions of the service contracts and data contracts. Don't expect to reconstruct the implementation of the original service from a WSDL file. In order to generate a client proxy which will allow you to call the service given this WSDL you could use the svcutil.exe utility.

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

Windows Communication Foundation Service Library Project

Do you know if there is any way to access the wsdl file when you create a WCF service library? It seems you can get it when you create a WCF application but not the service library...
Any ideas would be appreciated.
Thanks
The only way to access the WSDL is once you host and run the service. Otherwise, you cannot access it. So, create a host (or application as you are calling it) with a mex binding, then run the service and you should be able to access the WSDL.
Once you do this, you can save the WSDL as a file or something for later reference.
You cannot access the WSDL automatically. Of course if you compile the static WSDL into the service library, as a resource, you could then access it directly.
but what is it that you are trying to accomplish?
The "Service Description" is available inside a service. It is not the WSDL itself, but rather, the in-memory model of a service description. It includes the namespaces, the element names and types - everything in a WSDL, and more.
You can get at it with System.Web.Services.Description.ServiceDescription. Typically this is done within a ServiceHost, a ServiceHostFactory, or an IEndpointBehavior.