Exposing WCF metadata on a SiteMinder protected site - wcf

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#

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

Quick and easy implementation of a WCF web service, given wsdl?

I'm writing a client to access a SOAP webservice, that will be hosted by a third party. I have the WSDL and XSD that define the interface and the data.
I've had no problem in creating a service reference from the WSDL, but I'm having a problem in building a simple web service that implements it, that I can use to test against. (The third party's service isn't ready, yet, but even were it running, I'd still like to do my initial testing against my own test server, not against theirs.)
I've browsed around, and apparently I can use svcutil to generate an interface for the service:
svcutil.exe thewsdl.wsdl thexsd.xsd /language:c# /out:ITestService.cs
This generates a file containing the service interface definition. But now what?
I figured the easiest way to go would be to build a self-hosted service, so I created a new console app, and in it I implemented a class derived from the service interface definition, and fired it up with a ServiceHost.
It runs, and while it was running I was able to create a Service Reference in my client app. But when I try to call it, from the client app, I get an error:
The provided URI scheme 'http' is invalid; expected 'https'.
What is the easiest way to get around this? Is there a simple way to simply turn off authentication and authorization, and simply allow unrestricted access?
EDITED:
I'm adding a bounty to this, as the original question seems to have attracted no attention.
But let's get to the crux. I am trying to write a client against a customer's SOAP service. As a part of the development, I want to create my own test WCF service, that implements the same WSDL.
So I have a downloaded .wsdl file, and an associated .xsd file, and with them I want to create a service that I can test against, with VS2010's debugger.
It's not important to me whether this service runs standalone, or within IIS, or that it be production stable. All I want is a service that accepts the requests that the customer's site would accept, and return the responses to my client that I need it to return, in order to test my handling of them.
How do I get there? I've tried adding a WCF Service Library, and then using svcutil.exe within it to add my new service, but it doesn't seem to populate the app.config with the server-side boilerplate, and my attempts to reconstruct it haven't worked.
Since you want a full fledged service to call instead of mocking it.
Follow these steps:
Create new "WCF Service Application" project
Copy wsdl and xsd into project
select your wsdl file and look in the properties section and copy location from full path
Right click on the project in solution explorer and select "Add Service Reference..."
For the service address, paste the location of your wsdl that was copied in previous step and hit go. It should show the operations you are expecting for the service.
hit ok
It should generate all the objects for you including the interface and config file (although at this point is client side in the config- we will have to switch this to be the service)
Now you should add the service config section in the system.serviceModel section. Since I don't know the specifics of your wsdl what you should do is create the services node inside the system.serviceModel section and copy the endpoint node from the client node generated. For example below of services node, you can blank out the address for now:
<system.serviceModel>
<services>
<service name="YourService">
<endpoint address=""
binding="basicHttpBinding" bindingConfiguration="WeatherSoap"
contract="ServiceReference1.WeatherSoap" name="WeatherSoap" />
</service>
delete the client node in the config
In the service, it is implementing a different interface when it generated the project so you will want to replace the interface implemented with the one listed in the contract attribute in the endpoint above. Then implement its members and it should explode out the operations available. You can fill in whatever you want the service operations to return.
depending on what the wsdl has in it, we may need to do a few more things to allow the necessary bindings to run - like setting up for wsHttpbinding, netTCPbinding, etc.
I've used Moq to handle this. Basically in the unit tests you specify the interface (this would have been generated for you with adding the service reference or using svcutil) and what you want it to return if you call it.
example setup below:
var mock = new Mock<IFoo>();
mock.Setup(foo => foo.DoSomething("ping")).Returns(true);
So then when you want to moq out your service call
var myObject = new IFoo;
var resp = myObject.DoSomething("whateverwillbeoverriddenbyping");
and resp will be true.
There are other options than using Moq. The options all involve taking the interface and injecting a different version of it. For example, you could also do a constructor injection mock, by passing in the interface to your class constructor.

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.

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.

wcf Extract wsdl from WCF Service with Flattened WSDL

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.