日期:2014-05-17  浏览次数:20392 次

c# 调用wcf请求的问题
    string serviceUrl = "http://www.wcf.com/Service1.svc/GetData";

            var webclient = new WebClient();
            byte[] postData = Encoding.UTF8.GetBytes("test");
            webclient.Headers.Add("Content-Type", "text/xml;");
            webclient.Encoding = Encoding.UTF8;
            webclient.Headers.Add("ContentLength", postData.Length.ToString());
            byte[] responseData = webclient.UploadData(serviceUrl, "POST", postData);
            string rr = Encoding.UTF8.GetString(responseData);

这是代码 www.wcf.com我配置到本地了

这是wcf的代码

   [OperationContract]
        [WebInvoke(UriTemplate = "GetData", Method = "POST",
            RequestFormat=WebMessageFormat.Xml,ResponseFormat=WebMessageFormat.Xml)]
        string GetData(string test);

总是报错:远程服务器返回错误: (400) 错误的请求。求解!!!!

------解决方案--------------------
http://www.cnblogs.com/tearer/archive/2012/05/23/2514636.html看看这个吧,你得个蛋包子

------解决方案--------------------
 byte[] postData = Encoding.UTF8.GetBytes("test");
你传递的不是xml格式数据
  
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/