0

如果我使用Method = "POST",wcf 服务会给出“找不到端点”错误(.../SpellCheckerWcf.svc)。但是,GET 方法有效。我在stackoverflow中搜索了“找不到端点”主题,但没有一个没有帮助。如果您知道解决方案,请帮助我。

界面:

[ServiceContract]
public interface ISpellCheckerWcf
{
    [OperationContract]
    [WebInvoke(UriTemplate = "DoWork?params[document]={document}", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    Stream DoWork(string document);
}

班级:

public class SpellCheckerWcf :ISpellCheckerWcf
{
   public Stream DoWork(string document)
   {
       JsonFormat json = new JsonFormat();
       json.document = document;
   return WriteJson(json);
   }
   private Stream WriteJson(object value)
   {
       var javaScriptSerializer = new JavaScriptSerializer();
       var json =
           Encoding.UTF8.GetBytes(javaScriptSerializer.Serialize(value));
       var memoryStream = new MemoryStream(json);
       WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
       return memoryStream;
   }

网络配置:

在此处输入图像描述

服务标记:

<%@ ServiceHost Language="C#" Debug="true"
Service="SpellCheckerWeb.SpellCheckerWcf" 
Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
4

2 回答 2

0

我认为您不再UriTemplate需要在其中包含查询字符串信息:

UriTemplate = "DoWork?params[document]={document}"

尝试仅使用:

UriTemplate = "DoWork"
于 2013-06-27T22:28:01.443 回答
0

我认为您需要“WebGet”装饰

<WebGet(UriTemplate:="DoWork?params[document]={document}", BodyStyle:=WebMessageBodyStyle.Wrapped,
                RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Xml)>
于 2013-06-28T13:34:59.243 回答