我从下面的项目中调用了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)Bad Request。当我尝试在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);
答案 0 :(得分:0)
"/AddAttachment?User={0}&Engagement={1}&FileName={2}&DocumentTrasferID={3}&fileSize={4}&ActivityName={5}"
"/AddAttachment?userAlias={userAlias}&engagementName={engagementName}&documentTranferId={documentTranferId}&fileName={fileExtension}&fileSize={fileSize}&activityName={activityName}"
url模式和真实网址不一样,你的请求找不到这个方法