我创建了一个aspx页面,用作在Intranet上的其他位置托管的WCF服务的代理。目标是让页面不受跨站点脚本限制的限制,并且可以与任何WCF Web服务一起使用。.NET代理简单WCF服务不起作用
我有调用工作,我的调试器拿起请求,但数据不被发送,并为空。当在同一个域中不使用代理(jquery ajax)时,我确实有这个工作。 Fiddler2不会出于任何原因接收我的HttpWebRequest,所以我不能看到实际发送的内容。
任何想法?我发布数据的方式做错了什么?任何方式让小提琴拿起WebHttpRequest?
Proxy.aspx
// var data = Request.Form["d"];
// ProxyRequest r = JsonConvert.DeserializeObject<ProxyRequest>(data);
var r = new { ServiceName = "AccountService.svc", Type = "POST", MethodName = "AjaxFindCompany",
Data = "{\"AccountNumber\":null,\"Address\":{\"City\":\"Pittsburgh\",\"Country\":null,\"State\":\"PA\",\"Street1\":\"1 Ave\",\"ZipCode\":\"15222\"},\"BusinessName\":\"AUto\"}" };
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("{0}/{1}/{2}?{3}", "http://localhost:2749", r.ServiceName, r.MethodName, r.Data));
request.Method = r.Type;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader contentReader = new StreamReader(response.GetResponseStream());
Response.ContentType = response.ContentType;
Response.Write(contentReader.ReadToEnd());
IAccountService.cs
[OperationContract]
[WebInvoke(Method = "*", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
MatchCompanyResponse AjaxFindCompany(MatchCompanyRequest request);
AccountService.cs
public MatchCompanyResponse FindCompany(MatchCompanyRequest request)
{
AccountHandler handler = new AccountHandler();
return handler.FindCompany(request);
}
public MatchCompanyResponse AjaxFindCompany(MatchCompanyRequest request)
{
// after calling proxy.aspx the debugger captures here but
// request is null...
return FindCompany(request);
}
如果你的服务地址为localhost,你可以试试这个链接解决您的提琴手问题:http://www.fiddler2.com/Fiddler/help/hookup。 asp#Q-LocalTraffic –
另外,如果您还没有,请确保您确保您的网页和Web服务都配置为返回堆栈跟踪/完整的异常详细信息 - 这可能会揭示出特定问题。 –
最后,为了在WCF端进行详细的调试,您应该启用WCF诊断 - 在您的代码被击中之前,WCf pipelione中的某些内容显然会出错。这会告诉你那是什么。 –