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
Related
To start off, i have never coded a SOAP web request before in my life so this has been a learning curve of note.
I am busy writing a service that will make a soap request to a SageX3 web interface in C#. Net (obviously using Visual Studio). We already have similar request on another service that is supposedly working and I am using that as a reference. So took the (supposedly) same wsdl file and created a connected service reference that generated the Reference.cs file which should be the interface I must use to this soap request. But this request url uses a default url that I do not seem to be able to change. I have looked through the class definition and the properties in the interface like "endpoint" and such all seem to be read only. So I looked in the other project how that Refenrence.cs file looks which is completely different. The first part of my generated reference.cs looks like this:
Newly created reference.cs header:
If you look at the original reference.cs file, it is vastly different:
Original created reference.cs header:
What I notice is that the original has public class that also inherits from SoapHttpClientProtocol that will allow the user of that class to setup the url as reqiured. I do not have that option as my generated code is straight up an interface.
This brings me to my question, could it be that I have an invalid wsdl file or working from a different file as the original code?
Was the code generated differently as there might be a different tool used in Visual Studio?
Did the original author make changes to the reference.cs after it was generated? I think this is a possible answer that I need to add a class definition in the reference.cs file.
Or am I on the completely wrong track here.
I use the following code to invoke a webservice from wsdl dynamically, which is working perfectly:(see docs)
Now I want to have the raw data from the response. I found the following:
(Docs)
But to use that example I need a place to add the method attribute of the extension. Because I invoke the webservice method through reflection, I don't have the method definition in my code.
On the previous webpage they are talking about creating a soapextension to capture the raw messages.
But where do I need to apply the extension in the first code, to have a dynamic webservice invoker with the possibility to request the raw data?
I had to convert my code to use WCF instead of the legacy webservice support in C#.
It's also possible to create a class with methods defined in the WSDL file. This allows me to invoke the webservice dynamically like I already did. On the following site I found some example code: http://blogs.msdn.com/b/vipulmodi/archive/2006/11/16/dynamic-programming-with-wcf.aspx
To get the raw data the only thing I needed to do was adding a behaviour to the endpoint of the service. I learned how to do that on the following page: http://mbsguru.blogspot.be/2012/11/capturing-and-using-raw-soap-messages.html
I'm trying to figure out how the WSCF Blue DataContract generation feature works.
It's documented here: http://alexmg.com/post/2009/09/01/Data-contract-generation-is-now-available-in-WSCFblue.aspx
I have a set of WSDL and XSD files from which we can use the "regular" method to create web service code.
The service generated does not allow you to use data contracts at the client end, meaning we get lots of Array types instead of List types.
Or more accurately, we can't get Lists, only Arrays so this means it's not using DataContracts.
So, when generating service code on the server side I get two options.
Use the regular option, generates an abstract class from which we create a concrete Service class
Use the "Generate Data Contract" option. This creates a .cs file containing just classes representing the the Xsd types, no abstract classes for the service.
So if I then try to generate the service classes with the regular options, I now have lots of duplicate classes representing the Xsd types.
I clearly have the wrong end of the stick.
Has anybody managed to make WSCF.blue work with DataContracts instead of the XmlSerializer?
I'm new in web services and I'm developing a C# WCF service that is calling an external service from another company to get some client data (for example: name, address, phone, etc), this part is working fine so far.
The external service is based on a standard XML Schema, and other companies will have soon the same service generated from the same XML Schema, using the same name methods and returning the same type of xml file.
My first question is that after I complete this first implementation, there is any way to add “dynamically” the other external companies services, having the information of their URL/Ports/etc, or do I have to insert each on them manually as services reference in my internal service project every time I need to add a new one, then compile and re-deploy?
My second question is related with the data contract /members, my understanding is that even if they are returning the same XML files, their data contracts/members will be different, is that true? So I’ll have to make a specific code to read the information I need from their data contracts for each new external company?? If this is true I have been thinking to make a generic code to read the raw xml, is this the best choice?
While C# is a compiled language it does support pluggin architecture through MEF. You could use this and add a small plugin .dll for each of your sources.
That being said it's quite possible that all you need is a configuration list containing connection details for each of your sources and connecting to them dynamically. That will only work if they're using the exact same schema, so that the objects they serve will serialize the same for all sources. You will have to instantiate the proxy dynamically through code using that configuration then, of course.
I should add something for your second question. As long as you're the one defining the contract, it doesn't matter if their actual objects are different. All you care about on your end is the xml they serve, and that you can connect using your representation. In fact, you can generate the contract as a .wsdl document. Each of the service-implementer can then generate domain objects from that. On the other hand if you're not the one "owning" the contract, some of the sources may decide to do it slightly differently, which will cause you a headache. Hopefully that's not your scenario though.
Best of luck! :)
My first question is that after I complete this first implementation, there is any way to add “dynamically” the other external companies services, having the information of their URL/Ports/etc
Unfortunately yes, you will have add service, compile it and deploy every time
My second question is related with the data contract /members, my understanding is that even if they are returning the same XML files, their data contracts/members will be different, is that true?
If you will use auto generated every service will create different contracts. I would think about creating you own class and convert external classes using reflection and extension methods
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