使用webHttpBinding的WCF服务; 404错误

时间:2009-07-10 12:46:52

标签: c# .net wcf http wcf-binding

是否提供了一项服务,配置如下框所示,当参数不匹配时抛出404? 在这种情况下,参数是一个复杂的类型,每次调用SearchJson方法都会返回一个404 ... (甚至允许使用WebInvoke选项并且不使用UriTemplate吗?)

该服务已启动并运行(我可以使用“生成您的客户端来调用Testpage ..?wsdl”-stuff)

服务方法配置为:

    [OperationContract]
    [FaultContract(typeof(Exception))]
    [WebInvoke(ResponseFormat = WebMessageFormat.Json, 
            BodyStyle = WebMessageBodyStyle.WrappedRequest, 
            RequestFormat = WebMessageFormat.Json)]
    SearchResponse SearchJson(SearchRequest req);

任何想法如何解决这个问题?

顺便说一句。这就是我用来测试的...无论我改变什么参数,都返回404 ...当我将WebInvoke更改为WebGet并使用simple-type作为参数(如string)时,我只能触发不同的行为...然后我得到了405

WebRequest req = HttpWebRequest.Create("http://localhost:8800/SearchService/SearchJson");
req.Method = "POST";
req.ContentType = "application/json";
req.ContentLength = 354;
WebResponse resp = req.GetResponse();

这是配置:

  <service name="SearchEngine.SearchService" behaviorConfiguration="HTTPGetBehavior">
    <endpoint address="SearchEngine.SearchService" 
              behaviorConfiguration="ajaxBehavior" 
              binding="webHttpBinding" 
               contract="SearchEngine.ISearchInterface" />
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8800/SearchService" />
      </baseAddresses>
    </host>
  </service>

2 个答案:

答案 0 :(得分:1)

好吧,我明白了......

我不知道为什么,但是如果我使用“WebServiceHost”而不是“ServiceHost”来使用WCF-Service我至少可以通过...我的SearchRequest对象是空的,但我希望能搞清楚为什么..

答案 1 :(得分:0)

HTTP 404表示找不到请求的资源。这很可能是从IIS返回的,我会仔细检查您正在调用的服务的地址。

由于服务本身启动并运行,我会想到您在客户端使用的地址中存在拼写错误。