I'm trying to to generate web service proxy class using ServiceContractGenerator.
But the problem is that i want to recieve a "raw" xml from webservice (it may be a string or XmlNode, doesnt matter).
Is there any way to modify web service contracts before generating proxy or do something else to get what i need?
If you are talking about Wsdl then it should either been exposed from the webservice. or rather provided to you via .wsdl file.
Related
I am currently trying to consume a generated report as a webservice to integrate some data into our system. Because the service itself is generated, the response can change frequently as things are added to it. While the endpoint and response may change, the request body will always be the same (taken from soapui):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Execute_Report>
</Execute_Report>
</soapenv:Body>
</soapenv:Envelope>
I'm trying to figure out a way to make the above request for any endpoint (different reports) and allow for changes in the response. Ideally, I want to just return the raw XML of the response as I can allow for change easier with how I handle the XML if I'm not being tied to a data contract.
It is also worth noting that the service uses WS-Security and a Username/Password is passed as part of the request.
I've used WCF and the files generated from svcutil work great when I don't expect the service to change frequently. However because these webservices are generated change is expected, and if I can get away from it, I don't want to be at the mercy of re-generating a new file with svcutil whenever things change, or have to generate a file (and maintain) for all the different generated webservices.
At the end of the day the question is: How do I consume a webservice and return the raw XML while still being able to apply WS-Security to the request?
I kept searching around and found this answer:
.NET client authentication and SOAP credential headers for a CXF web service
This allowed me to do what I was after.
I have a WSDL definition for a SOAP service and I have successfully generated *.cs file from it using SvcUtil.
Implementing client is quite straightforward - I just need to call the necessary functions from the generated *.cs and that's it.
Implementing server seems more complicated. As I understand I need to implement an interface from the generated *.cs and then use some magic to turn it into the web server.
But I don't need a new web server, I already have a web server written in C# which already has many functionality unrelated to the SOAP service that I need to implement. I don't want to create another web server but I want my SOAP service to be just a part of my existing application (server), that is my server can answer e.g. requests http://example.com/request1, http://example.com/request2 etc. and I want this SOAP service to be just http://example.com/request3.
Since HTTP is already handled by my server I don't need .NET to handle it for me, basically my server can accept client connections and call the necessary handler based on the URL. I have a handler for SOAP request which looks approximately like this:
MyResponse HandleSOAPRequest(MyRequest request)
{
// 1. parse soap message from request.body
// 2. process it
// 3. generate response, serialize it in SOAP format and return it
}
The question is - can I rely on WSDL definition and .NET libraries to do it?
Currently I'm parsing SOAP request using XDocument and manually extract fields from it and serialize using simple string concatenation. Using .NET built-in functions to serialize or parse XML doesn't work. That is if I try to serialize response from an object of the class defined in the generated *.cs file then produced XML is different from what is expected by the protocol, similarly, if I try to parse request as an object of the class defined in the generated *.cs file I get error because XML parser expects different format. This applies to both the SoapFormatter and XmlSerializer.
Since .NET can implement client this means that everything that is necessary to parse and serialize SOAP messages is already implemented, I just need to figure out a way how to use this functionality.
The documentation for ServiceModel wasn't very helpful.
The easiest way would be to start the service via the ServiceHost:
ServiceHost host = new ServiceHost(typeof(YourService));
host.Open();
(I assumed here the configuration will come from the app.config and will not be setup in code like in the linked example below.)
How to: Expose a Contract to SOAP and Web Clients
The only drawback of this is that the application has to run with admin rights or otherwise a weird cofiguration is necessary.
I'm writing WCF service. I need to pass XML to service and then to write that XML to database which is not important right now. Something like this:
[OperationContract]
void InsertReport(XmlObjectSerializer xmlDoc);
Anyone did this?
[EDIT]
I also need to test this, but WCF default client cant do that...
You can easily solve this by generating a sting from the xml. The saved data in the database will always get converted to a string anway.
I am going to have XML output from web service. in fact, I write a method in web service that returns a first of objects, now I want to have this list of objects in XML format in client side.
Does web service produce XML output?
If yes, how can I get XML in client side?
I don't want to write XML document in web service
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
return
<string>Hello World</string>
Please help me
I'm not entirely sure your question makes sense:
does web service produce XML output?
It can pretty much return whatever you like. You can make it return raw xml, you can make it return XmlNode-objects, or something similar.
This is what confuses me:
I don't want to write XML document in web service
Does this mean you don't want to build the XML-object at all, on the server side? If so, it will be up to your client to create the xml. How you can do that obviously depends on what data you are returning. I don't think there is any "magic" in c# that will do this for you automatically, just because it is a response from a WS.
Regarding your specific issue, you can find some guidance here.
When defining the details of your data contract and your WCF endpoint, you can decide the exact communication protocol and the form used to return your results. There, you could set the options of using REST or SOAP (see this for more) or returning results as JSON or raw data.
Hope I helped!
My project has DLL which implement Web Client functionality. How can I get XML request which is send to WCF service from that DLL? My call of DLL method looks like this:
LocalUser usr = DLLServiceProxy.GetUser("JohnS");
If it's for debugging purpose then you can check the svclog. If it's not for debugging purpose , then you will have to change the code in the dll so it returns that xml. Why would you want to have that xml?
More info on how to configure svclog
I'd try to use some http sniffers, like Fiddler, this one (not tested it by myself), or something else