我从下面的项目中调用了 Rest WCF 服务
userAlias = "test";
var url = new StringBuilder();
url.Append(
string.Format("https://webdemo-t.orioninc.com:8443/Services/2012v2/TestService.svc/AddAttachment?User={0}&Engagement={1}&FileName={2}&DocumentTrasferID={3}&fileSize={4}&ActivityName={5}",userAlias, engagementName, fileName, documentTranferId, fileSize, activityName));
WebRequest request = WebRequest.Create(url.ToString());
CurrentUrl = url.ToString();
var networkCredential = new NetworkCredential("jame", "test", "company");
request.Credentials = networkCredential;
WebResponse response = request.GetResponse();
Encoding encoding = Encoding.GetEncoding(1252);
var responseStream = new StreamReader(response.GetResponseStream());
string responseResult = responseStream.ReadToEnd();
responseStream.Close();
Console.WriteLine(responseResult);
调用这些服务时出现异常远程服务器返回错误:(400)错误请求。当我尝试在 WCH 实现方法中返回一个正常的字符串时,我得到了正确的 webresponse 结果。我该如何解决这个错误?
WCF实现方法
public string AddAttachment(string User, string Engagement, string FileName, string DocumentTrasferID, string fileSize, string ActivityName)
{
dynamic _Trackerfaccade = new KPMG.EauditEmailService.Facade.EAppEmail();
string Result = _Trackerfaccade.AddAttachment(User, Engagement, FileName, DocumentTrasferID, fileSize, FileName);
return Result;
}
运营合同
[OperationContract]
[WebGet(UriTemplate = "/AddAttachment?User={userAlias}&Engagement={engagementName}&FileName={FileName}&DocumentTrasferID={documentTranferId}&fileSize={fileSize}&activityName={activityName}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string AddAttachment(string userAlias, string engagementName, string documentTranferId,string fileName,string fileSize,string activityName);