Web Service to get XML from client in C# - c#

I want to get an XML response from Client by using Web service.For this i am going to create a web service that can take XML , so that they can use the web service to send the XML to me.
Remember in this i have to create both ends.
Somebody please advise on this...
public XmlDocument GetXmlDocument(string pXML)
{
// Create an XmlDocument object.
XmlDocument xmlDocumentObject = new XmlDocument();
xmlDocumentObject.LoadXml(pXML);
// Return the created XmlDocument object.
return (xmlDocumentObject);
}
The above code will take take any XML as string . How could my client will use this method on there end and send the response to me.

Related

Accepting SOAP envelope

Cheers,
I have a soap webservice written in c#, that takes in an XMLDocument as parameter...
[WebMethod]
[SoapDocumentMethod(ResponseNamespace = "http://ns.ctb.nl/flex/2012-1")]
public string stuurReflexBericht(XmlDocument m) //XElement m
{
//do something
}
and Im using Boomerang, an extension for Google Chrome to test the service.
Boomerang creates this Request Body:
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://ctb.nl/webservices">
<x:Header/>
<x:Body>
<web:stuurReflexBericht>
<web:m>
My XML Body
</web:m>
</web:stuurReflexBericht>
</x:Body>
</x:Envelope>
and this works, the service receives the xml message. However, the consumer of the service wants to send the message as:
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://ctb.nl/webservices">
<x:Header/>
<x:Body>
My XML Body
</x:Body>
</x:Envelope>
and when they do that, the XMLDocument is null.
The consumer does not want to change their code, so its up to me to make the adjustments.
I tried changing the parameter datatype from XMLDocument to string in the hopes that it would work, but it does not.
Any ideas on how to solve this?
TIA

Get XML of Request and Response to a web service

In c# using Asp.net, I am trying to get the XML format of the request and response I am making to a web service. I used one of the solution from this site but it is incomplete in my situation. I am able to serialize the response but I cannot do the same for the request since I am sending in multiple parameters as request and I cannot completely figure this out.
Example :
RefreshInfo info = refreshclient.getRefreshResponse(refreshcontext, itemID);
I added the below code for response and I could see the XML format of it.
XmlSerializer xmlSerializer = new XmlSerializer(info.GetType());
using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, info );
string repsonsexml = textWriter.ToString();
}
How can I do the same for the request from this?
Help is appreciated.. Thank you!!
I think the answer is right here. Posted too early, I suppose!
Generating XML from multiple classes?

Can I post XML data to a Restfull service

I have an application that will be posting an XML object to me.
Is it possible to create a Restful service (I'm assuming using Win API) to post the data to, or should I be using WCF services?
You can do this with WebAPI by just reading the content stream from the request:
public XmlDocument ReadRawXml(HttpRequestMessage request)
{
var xmlDoc = new XmlDocument();
xmlDoc.Load(request.Content.ReadAsStreamAsync().Result);
return xmlDoc;
}
You can call that in your WebAPI code.

C# object validate against xsd file

The question is can I validate c# object against xsd without serializing this object to the xml? If yes, please give me some quick sample.
Just to give You some introduction. I got reference to the external WCF service and I got some xsd file. I got some proxy objects requests/response for this service. In the service consumer side (just class library) I would like to validate response (c# object) against provided xsd. Can I do that without serializing response to the xml?
public Response Consume(Request message)
{
try
{
ServiceClient serviceClient = new ServiceClient();
var response = serviceClient.Execute(message);
// Here I would like to validate response without serializing against xsd
return response;
}
catch (FaultException<ValidationFault> validationException)
{
throw validationException;
}
}

How to sign an xml file in a wcf service?

I'd like my WCF service to return an xml file that has been signed.
I found documentation that shows how to sign an XmlDocument on msdn, but since a WCF function can't return an XmlDocument I'm not sure if the following would work (similar to thisquestion)
public XmlElement GetXml() {
var doc = new XmlDocument();
// add data to doc
// sign doc
return doc.DocumentElement;
}
Would it still be possible to verify the signature of doc.DocumentElement if I added it to another XmlDocument after a client requested it? Is there a better way to do this?
Thanks!
XmlDocument is not decorated with DataContractAttribute and I cannot see why the object needs to be sent over the wire while the serialized form (text form) is all that is required.
I would design it as:
[OperationContract]
string GetFooXml();
And send the string. That is what WCF/XML is for, sending data as text whenever possible so that more kinds of clients can consume it.

Categories

Resources