, , XML, WCF REST ( ), . , , , Google, URI (, - XML, URI). , , , , WCF , "400 Bad Request". , WCF XML, , - (, Microsoft?) .NET. ). , ).
** IMyRESTService.cs( ) **
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Bare)]
Stream Receive(Stream text);
** **
XmlDocument MyXmlDocument = new XmlDocument();
MyXmlDocument.Load(FilePath);
byte[] RequestBytes = Encoding.GetEncoding("iso-8859-1").GetBytes(MyXmlDocument.OuterXml);
Uri uri = new Uri("http://localhost/MyRESTService/MyRESTService.svc/Receive");
Request.ContentLength = RequestBytes.Length;
Request.Method = "POST";
Request.ContentType = "text/xml";
Stream RequestStream = Request.GetRequestStream();
RequestStream.Write(RequestBytes, 0, RequestBytes.Length);
RequestStream.Close();
HttpWebResponse response = (HttpWebResponse)Request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string ResponseMessage = reader.ReadToEnd();
response.Close();
** XmlContentTypeMapper.cs( , WCF XML) **
public class XmlContentTypeMapper : WebContentTypeMapper
{
public override WebContentFormat GetMessageFormatForContentType(string contentType)
{
return WebContentFormat.Raw;
}
}
** Web.config( )
<endpoint binding="customBinding" bindingConfiguration="XmlMapper" contract="MyRESTService.IMyRESTService"
behaviorConfiguration="webHttp" />
<bindings>
<customBinding>
<binding name="XmlMapper">
<webMessageEncoding webContentTypeMapperType="MyRESTService.XmlContentTypeMapper, MyRESTService"/>
<httpTransport manualAddressing="true"/>
</binding>
</customBinding>
</bindings>
- WCF HTTP POST
http://social.msdn.microsoft.com/forums/en-us/wcf/thread/4074F4C5-16CC-470C-9546-A6FB79C998FC