简体   繁体   中英

Why When I Type “POST” Method for Wcf Service It Gives “Endpoint not found” Error?

If I use Method = "POST" , wcf service gives "Endpoint not found" error(.../SpellCheckerWcf.svc) .However , GET method works. I searched "Endpoint not found" subject in stackoverflow but none of them did not help. If you know the solution , please help me.

Interface:

[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);
}

Class:

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;
   }

Web Config:

在此处输入图片说明

Service Markup:

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

I don't think your UriTemplate needs to have query string info in it any more:

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

Try using just:

UriTemplate = "DoWork"

I think you need the 'WebGet' decoration

<WebGet(UriTemplate:="DoWork?params[document]={document}", BodyStyle:=WebMessageBodyStyle.Wrapped,
                RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Xml)>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM