我有一个在VS2015中启动的WCF服务。然后客户端代码在另一个VS2015 ..我不断得到"远程服务器返回错误(404)Not Found"错误。当我将参数添加到网址" http://localhost:53989/FileShareService.svc/UploadFile/WTM"工作正常,但如果我添加为encoding.GetBytes我得到错误。
int a = A::B::Val1;
客户端代码不起作用:
[ServiceContract]
public interface IFileShareWebService
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "UploadFile/{patron}",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
void UploadFile(string patron);
}
客户端代码工作:
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "patron=WTM";
byte[] data = encoding.GetBytes(postData);
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:53989/FileShareService.svc/UploadFile/WTM");
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = 0;
//httpWebRequest.GetRequestStream();
// Code to write data to the stream
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
requestStream.Write(data, 0, data.Length);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}