Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#WCF Web服务接受XML数据时出现问题_C#_Xml_Wcf_Http_Rest - Fatal编程技术网

C#WCF Web服务接受XML数据时出现问题

C#WCF Web服务接受XML数据时出现问题,c#,xml,wcf,http,rest,C#,Xml,Wcf,Http,Rest,我已经在C#中创建了一个基本的WCF REST web服务,需要它在HTTP POST中接受“application/xml”的内容类型。只有当帖子的内容类型为“application/x-www-form-urlencode”时,我的代码才会起作用,当我尝试将帖子的数据内容类型设置为“application/xml”时,我会收到一条400错误消息 WCF web服务正在使用“RestBehavior”的行为配置和“webHttpBinding”的绑定 撰写和发送帖子的客户端代码如下所示: Ht

我已经在C#中创建了一个基本的WCF REST web服务,需要它在HTTP POST中接受“application/xml”的内容类型。只有当帖子的内容类型为“application/x-www-form-urlencode”时,我的代码才会起作用,当我尝试将帖子的数据内容类型设置为“application/xml”时,我会收到一条400错误消息

WCF web服务正在使用“RestBehavior”的行为配置和“webHttpBinding”的绑定

撰写和发送帖子的客户端代码如下所示:

HttpWebRequest request = (HttpWebRequest) WebRequest.Create(GetURL());
request.Method = "POST";
request.ContentLength = byteArray.Length;
request.ContentType = "application/xml";
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
Stream data = response.GetResponseStream();
response.Close();

当我将内容类型更改为“application/x-www-form-urlencoded”时,它可以工作,但是这里的客户机代码从web服务中得到一个400错误。我需要它来处理“application/xml”的内容类型。谢谢。

“我收到一条400错误消息”-这是您的客户错误。启用跟踪以查看服务抛出400的原因。如果您的xml不是WCF期望的格式,则您将收到此消息。