【问题标题】:WCF Service with webHttpBinding; 404 error带有 webHttpBinding 的 WCF 服务; 404错误
【发布时间】:2009-07-10 12:46:51
【问题描述】:

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

服务已启动并正在运行(我可以使用“生成您的客户端 ..?wsdl”-stuff 调用测试页面)

服务方式配置为:

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

有什么办法解决这个问题吗?

顺便说一句。这就是我用于测试的东西...无论我更改什么参数,都会返回 404 ...当我将 WebInvoke 更改为 WebGet 并使用简单类型作为参数(如字符串)时,我只能触发不同的行为...然后我得到一个 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>

【问题讨论】:

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


    【解决方案1】:

    好的,我明白了……

    我不知道为什么,但是如果我使用“WebServiceHost”而不是“ServiceHost”来使用 WCF 服务,我至少可以通过请求获取请求。我的 SearchRequest 对象是空的,但我希望能弄清楚为什么..

    【讨论】:

    • WebServiceHost 将执行此操作所需的所有花哨的 REST 技巧。您将需要使用 WebServiceHost 代替常规 ServiceHost(它需要 SOAP 格式的消息)
    • 什么是 webservicehost 我在我的配置文件中根本看不到服务主机?
    【解决方案2】:

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

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

    【讨论】:

    • 不,这是不可能的;)函数调用中肯定没有错字...
    猜你喜欢
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 2014-02-23
    • 2013-10-10
    相关资源
    最近更新 更多