我认为这与您的网络服务设置有关。最好只为新服务创建 GET、POST、Put、DELETE 心跳调用,然后从 fiddler 中检查这些调用。如果您收到 401,则可能意味着您的应用程序池身份无法访问某些内容。
解决该问题的步骤:
- 在您的 WCF 发布文件夹中授予用户读/写/修改/执行/..similar 权限
- 在集成的 .net 4 中为此站点创建应用程序池
- 将此用户设置为应用程序池标识,启用匿名模式
- 启用 PUt,同时删除动词
服务中用于测试调用的心跳类的一部分:
[DataContract]
public class StatusInfo
{
[DataMember]
public string MachineName { get; set; }
[DataMember]
public string IpAddress{ get; set; }
[DataMember]
public string Methodname { get; set; }
public override string ToString()
{
return "Machinename:" + MachineName + " ;IP:" + IpAddress + "; Method:" + Methodname;
}
}
private void ResolveStatus(StatusInfo statusInfo,string methodname)
{
try
{
var context = System.ServiceModel.OperationContext.Current;
RemoteEndpointMessageProperty property =
(RemoteEndpointMessageProperty)
context.IncomingMessageProperties[RemoteEndpointMessageProperty.Name];
statusInfo.IpAddress = property.Address;
statusInfo.MachineName = Environment.MachineName;
statusInfo.Methodname = methodname;
}catch(Exception ex)
{
}
}
/// <summary>
/// create task
/// </summary>
/// <param name="taskwrapped"></param>
[WebInvoke(Method = "POST", UriTemplate = "", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public StatusInfo postcall()
{
StatusInfo statusInfo = new StatusInfo();
logger.Trace(Tagname + "postcall");
ResolveStatus(statusInfo, "POST");
return statusInfo;
}
/// <summary>
/// edit task
/// </summary>
[WebInvoke(Method = "PUT", UriTemplate = "", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public StatusInfo Edit()
{
StatusInfo statusInfo = new StatusInfo();
logger.Trace(Tagname + "Edit");
ResolveStatus(statusInfo, "PUT");
return statusInfo;
}
//delete request with taskid
[WebInvoke(Method = "DELETE", UriTemplate = "", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public StatusInfo DeleteCall()
{
StatusInfo statusInfo = new StatusInfo();
logger.Trace(Tagname + "Edit");
ResolveStatus(statusInfo, "DELETE");
return statusInfo;
}
//delete request with taskid
[WebInvoke(Method = "DELETE", UriTemplate = "/{recordid}", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public StatusInfo DeleteCallWithParam(string recordid)
{
StatusInfo statusInfo = new StatusInfo();
logger.Trace(Tagname + "Edit");
ResolveStatus(statusInfo, "DELETE/"+recordid);
return statusInfo;
}
enter code here