Getting methods from web service and their parameters programmatically - c#

I'm playing around with WCF and wondering about the following. I'd like to be able to get a list of all available service methods and parameters associated with these methods.
Now, I've tried to work with the ServiceDescription namespace, but it seems flawed. For one .svc it works, for another it doesn't.
What would be an okay way to approach this? Any tips?

You could just download the WSDL of the webservice and parse that (it is XML, see http://www.w3.org/TR/wsdl) since the WSDL contains all information like interfaces/methods/parameters etc.
Some helpful resources including source code for doing what you want:
http://webservicestudio.codeplex.com/
http://wizdl.codeplex.com/
http://soap-sec.sourceforge.net/

Related

Calling a Java webservice from C# .NET Core (specifically Workday). How to get xml attributes in the soap request

I am trying to call Workday's web service in .net core c#. The service was written in Java. I'm having problems getting xml attributes to show up in my soap request.
Example: What I want it to look like:
...
<wd:Usage_Data wd:Public="true">
<wd:Type_Data wd:Primary="true">
<wd:Type_Reference>
...
What it does look like:
...
<wd:Usage_Data>
<wd:Type_Data>
<wd:Type_Reference>
...
I cant get the wd:Public="true" to be there in the send request xml output. I am setting it in c#.
What I've done is create a WCF Service Reference to workday, and modified the Reference.cs to https://hr.dovetailsoftware.com/gcox/2014/06/13/getting-started-workday-web-services-using-c/, and tried playing around with the xml serializer a bit, but no luck. Other workday services that don't have any attributes work just fine.
I'm sure its a simple fix but I cant find it. I can post more code if necessary. Thanks
Figured it out. I think it's a Wrokday thing. Posting here in case of anyone else. You actually need to set the "Specified" properties.
phoneType.Usage_Data[0].Public = true;
//not good enough, you need to set this
phoneType.Usage_Data[0].PublicSpecified = true;

.Net Web Services XML Serializer

I am using VS2015 to consume some old web services (SAP). I can import the WSDL just fine, and all the references come across ok. But, when I try and use the service, it looks like the XML output only includes properties with values. That is not working with the WSDL service. I am using SoapUI to test and it can communicate just fine with the service. Using SoapUI, if I remove some of the outbound XML in the call, it will fail. So, I think my issue is the outbound XML serialization. Any ideas on how to tackle this? Is there a way to mark the properties so they will be output even if they don't have a value? (short of putting a space or something in the field? Thanks.
This is by design to differentiate between null and empty, have a look at Suppress Null Value Types from Being Emitted by XmlSerializer

how to use keyvaluepairofstringdouble returned from c# webservice

I have a web-service method that returns a
List<KeyValuePair<string,double>>
However when I use use that method in a service reference, the object it returns is
List<KeyValuePairOfStringDouble>
I cannot figure out how to use this.
Your service reference is trying to make the best out of the WSDL it gets. But your service and your application have been playing games with each other. They were never allowed to directly talk. So you are now stuck with something that looks like what you need and is called like what you need, but it is not exactly what you need.
Simple solution is to build a new list that is what you syntactically need:
List<KeyValuePair<string,double>> yourlist = serviceResult.Select(kvp => new KeyValuePair<string, double>(kvp.Item1, kvp.Item2)).ToList();
For a better solution in the future you should let both ends of your service communication know what the other end is up to syntactically. This is called a contract assembly.
This thread on StackOverflow and the links that it contains might be a good start if you want to build one for your service.

Adding similar Web Services to .NET C# application

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

WCF REST issue: where is service.basic.svc.cs

I just started to use WCF Rest project template to design a REST service, for example Collection REST WCF Collection service.
One thing I noticed that the Service.basic.svc.cs file is no longer under the Service.svc as its partial or dependent class file. I tried to find the definitions for CollectionServiceBase and ICollectionService in Service.svc.cs:
public class Service :
CollectionServiceBase<SampleClass>, ICollectionService<SampleClass>
...
those two classes are actually in my %temp% folder as readonly files. It looks like that they are not for editing. How can I make changes of their attributes such as UriTemplate strings? Not sure if I can bring those files back to the project so that I have control of those files (change definitions or remove some interfaces)? I think there may be reason to this change (compare to the example in some of video shows by endpoint.tv Screencasts).
OK. Finally I got an answer at ASP.Net forum, WCF REST Startkit discussion group saying that the codes in Service.basic.svc.cs are moved to Microsoft.ServiceModel.Web.dll. This makes it hard to customize some class attributes to customize template url or xml node names. I was suggested to get the source codes to make changes if I need, but I don't think it is good idea.

Categories