I hit my head against the wall for two days with this, hope someone can give me a hand. I have a RESTful web service that I wrote using WCF; for this there is nothing just two methods that take a single string parameter, and also return a string. Both parameters and return value are direct XML.
[ServiceContract] public interface IService { [OperationContract] [WebGet(UriTemplate = "/method1/{data}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)] string Method1(string data); [OperationContract] [WebGet(UriTemplate = "/method2/{data}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)] string Method2(string data); }
For the argument, we can say that the implementation of both of these methods looks like this:
public string Method1(string data) { return string.Format("You entered: {0}", data); }
If I go to http://myuri.com/service.svc/method1/foo, the following is written in the browser:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">You entered: foo</string>
This works fine, but if I change the URL to: http://myuri.com/service.svc/method1/ <foo> I get 400 (invalid request). So I turned on some indicators to see what was happening using the following code:
<system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="All"> <listeners> <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "c:\Traces.svclog" /> </listeners> </source> </sources>
As you can see, I use the value of the "All" switch to capture every event that occurs during the execution of this service. I came back several times using the URL format, which works to check if the tracing devices were working, and they were. Then I went to the URL containing the XML tag foo and got a 400 error as expected, but when I returned to the log file, no additional information was added to the end. This leads me to believe that error 400 is displayed before calling the WCF service.
Finally, I switched methods from GET methods to POST methods, wrote some code using WebRequest / WebResponse with the same result. Now I read a few posts on how to use the client-side XmlSerializer to send data to the service, but this defeats the purpose of this service. Although I use .NET to record the service, it is likely that PHP or classic ASP scripts will connect to this service, and they obviously do not have access to the XmlSerializer.
So my million dollar question is: is it possible to send a βrawβ XML request to the RESTful web service developed by WCF, and if so, how?
PS XML entering and leaving a service is not based on any material object, but simply on the structure that I created for use with this service. The XML arrival is processed through XPath, the values ββare placed in a large XML string and passed to the external API. The results of this API are processed and then returned by the RESTful service.
Any help would be greatly appreciated!