首页 新闻 会员 周边

.net调用webservice时出现500服务器错误

0
悬赏园豆:20 [已解决问题] 解决于 2017-06-19 16:24

代码如下

            string url = "http://10.17.128.93:8006/FEDZ_GetLCData.asmx?op=GetLCInfo";
            //设置post方式
            string method = "POST";
            StringBuilder sb = null;
            sb = new StringBuilder();
            sb.Append("StartDate=" + DateTime.Now);
            sb.Append("EndDate=" + DateTime.Now.AddDays(1));

            WebClient wc = new WebClient();
            byte[] postData = Encoding.UTF8.GetBytes(sb.ToString().Trim());
            wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            wc.Headers.Add("ContentLength", postData.Length.ToString());
            byte[] getdata = wc.UploadData(url, method, postData);
            wc.Dispose();
            //处理返回数据(一般用json)
            string srcString = Encoding.UTF8.GetString(getdata);

   byte[] getdata = wc.UploadData(url, method, postData);这里出现500错误,原因是什么?

雍饱的主页 雍饱 | 初学一级 | 园豆:182
提问于:2017-06-19 09:40
< >
分享
最佳答案
0

服务器内部错误,排查服务端代码。

如果你没有服务端代码,检查你的数据是否按要求格式上传。

收获园豆:20
hahanonym | 小虾三级 |园豆:1460 | 2017-06-19 09:49

POST /FEDZ_GetLCData.asmx HTTP/1.1 Host: 10.17.128.93 Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/GetLCInfo" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetLCInfo xmlns="http://tempuri.org/"> <StartDate>string</StartDate> <EndDate>string</EndDate> </GetLCInfo> </soap:Body> </soap:Envelope>

这是服务器代码我把application/x-www-form-urlencoded改成 text/xml还是不行。

雍饱 | 园豆:182 (初学一级) | 2017-06-19 10:17

@雍饱: 可以理解为,你调用的服务器端方法出现了异常,可能是你传参没按要求格式传,这个需要联调

hahanonym | 园豆:1460 (小虾三级) | 2017-06-19 11:39

@hahanonym: 怎么联调。。。

雍饱 | 园豆:182 (初学一级) | 2017-06-19 11:41

@雍饱: 客户端和服务端一起调试

hahanonym | 园豆:1460 (小虾三级) | 2017-06-19 14:24

@hahanonym:  谢谢了   问题已经解决了,用的版本不对导致的。

雍饱 | 园豆:182 (初学一级) | 2017-06-19 16:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册