I have generated a class using wsdl.exe from the wsdl file.
I inspected the generated code and there is like 3-4 methods available but I guess only by soap protocol(I'm just guessing & probably wrong) which is defined with the attribute above like:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute(etc..)]
Simply, I want to create a dummy class from the wsdl and use its methods.
Thanks in advance.
I would recommend using svcutil.exe instead of wsdl.exe
Using svcutil makes it really easy to make a "dummy" class (which I am reading as a stub or mock) as it generates an interface as well as a proxy.
So, for example,
svcutil.exe http://www.restfulwebservices.net/wcf/CurrencyService.svc?wsdl
will generate an interface called ICurrencyService and a CurrencyServiceClient.
The visual studio command prompt has an exe that should allow you to do this.
wcftestclient.exe [service end point address]
hopefuly thats what you mean.
Related
We have a xsd file in which the contracts are already defined. We use xsd.exe to generate classes for our WCF service, and use the XmlSerializerFormat for our webservice again.
It seems to me, that this is a weird thing to do, to have WCF generate a new XSD for the classes which the xsd.exe generated for us, while we have already have our XSD definition right there for the taking..
While xsd.exe does a nice job of generating classes for us, it also simplifies complextypes as you can see in my previous question; meaning, the xsd actually changes a bit when it generates classes and are used in the webservice again; the ArrayOfStringXXX problem..
Can we tell the WCF service to use our own xsd file for its contract, instead of generating a new contract based on what the xsd.exe delivers?
What I tried:
I already looked at this sample: IWsdlExportExtension interface sample which seems promosing, but I was not able to replace the xsd in the export method, because it was never
called.
TL;DR: Can we point our WCF service to our own xsd file, instead of letting it generate it's own?
Thanks
You can use tools like WSCF.blue to generate the data contract classes from your XSD file. I have experience from this and it works OK for most cases. See this blog for a good explanation.
There are also other tools that enable this, see this question for some suggestions.
There also seems to be a new option in Visual Studio 2012 for this, see the documentation. I haven't checked this out myself.
This development method is referred to as contract first, so you will find yet more info on Google :-)
I want to use svcutil to generate only the interface for the service contract, and the corresponding data contracts for the inputs and outputs.
However, I want to prevent svcutil from generating the Service Clients and Channel. Is there an option to do this?
I'm in the same boat at you. Take a look at this tool http://wscfblue.codeplex.com/ there's an option for service-side stub that will skip all the ClientBase stuff generated by SvcUtil.
Let me know how this works for you.
This is a partial answer:
You can use the "/dataContractOnly" option to only generate the data contracts for a service. However, this won't create the service contract, like you're looking for.
Depending on the footprint of the service, it may be a simple process to simply remove the generated channel and client code, from the output file(s).
I'm trying to find a way to read in a WSDL file (I will not have the source of the service) that requires a custom type as input.
I am currently trying to test with this file http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
So in this I am dynamically calling the ConversionRate method. I input two strings for the "ToCurrency" and "FromCurrency" fields needed and then I use String.Format and create a class named the same as the expected one "Currency" in this case and I've made the to/from currency as public strings in the class I create and set them to the two input strings I gave in the beginning. When I try to invoke the service this way I get an error like cannot convert type Currency to Currency.
I assume this is because the class I've created is not the same as the one implemented in the code for the service I'm calling.
My question is this, can I create a class of the appropriate type to successfully pass in and invoke the method using only the data I get from the WSDL file?
Use Microsoft's wsdl.exe link.
wsdl.exe http://www.webservicex.net/CurrencyConvertor.asmx?wsdl
The tool can be found in your Microsoft SDK folder under program files. If all you want is to consume the web service, then Jen's suggestion is best imho.
You can have the WSDL tool automatically generate proxy classes to work with the service: How to consume a Web service in visual studio from only the wsdl
My service uses a type Foo defined in another DLL, and my client also uses that DLL to get that type. Rather than generating a proxy class for that type, I'd like the proxy code to just refer to the real type. I can accomplish this manually by generating the proxy with WSDL.EXE on the running service, manually editing out the partial class Foo definition from it, and adding a Using statement. I'd like to do it without hand-editing if possible.
It seems like maybe the answer is to use SVCUTIL.EXE instead of WSDL.EXE. There are two intriguing options: /R and /ET. I tried putting /ET:Foo and /ET:My.FQN.Util.Foo, and /ET:www.my.com.the.servicenamespace.Foo, and also adding the DLL filename to the option. But nothing changes in the ServiceWithFoos.cs proxy class that gets created. The partial class definition for Foo is still there.
Am I on the right track? What am I doing wrong?
Add [DataContract(Namespace = "http://anything.here")] to your Foo type, then use svcutil with the /r option taking the path of the library containing Foo. This way svcutil should see the same contract namespace and map Foo correctly.
I have been playing around in PHP with it and got something to work, what i did was:
$client = new SoapClient("http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl");
$fetchedArr = $client->GetCityForecastByZIP(array("ZIP" => "10451")); //get the weather in the bronx YO!
And now i would like my application i WPF/C# to do the same. What is the equivalent in c#?
The simplest way is to use VS and add a web reference. This automatically creates the stub for you
You can use the WSDL tool to generate a C# file which will contain the necessary types and members to talk to the web service or you could add a Web Service reference. See here for more details.
If your preferred approach is to control the generated code, it's best to use the more recent SvcUtil.exe in place of Wsdl.exe.
See also WCF proxy generation: svcutil.exe vs wsdl.exe
Adding web service reference to your project n making a call to the service exposed methods is your best bet . It does the trick n you're out of the hassle of creating SOAPs manually
You can use the "wsdl.exe" command from the .NET SDK to generate the wrapper classes if you don't want or like to use Visual Studio.
see:
http://msdn.microsoft.com/en-us/library/7h3ystb6%28VS.80%29.aspx