使用webHttpBinding的WCF服务; 404错误

时间:2022-06-02 00:15:50

does a service, which is configured like in the box below, throwing a 404 when there is a mismatch in the parameter? In this case the parameter is a complex type and every call to the SearchJson method returns a 404... ( is it even allowed with the WebInvoke option and WITHOUT the UriTemplate? )

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

The service is up and running ( i can call the Testpage with the "Generate your client ..?wsdl"-stuff )

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

The service method is configured as:

服务方法配置为:

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

Any ideas how to solve this?

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

btw. this is what i use for testing... no matter what parameter i change, a 404 is returned... i can only trigger a different behavior when i change the WebInvoke to WebGet and use a simple-type as parameter ( like string )... then i get a 405

顺便说一句。这就是我用来测试的...无论我改变什么参数,都返回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();

Here is the the config:

这是配置:

  <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 个解决方案

#1


ok, i got it...

好,我知道了...

i don't know why, but if i use "WebServiceHost" instead of "ServiceHost" to employ the WCF-Service i can at least get the requests through.. my SearchRequest object is empty, but i hopefully will figure out why..

我不知道为什么,但如果我使用“WebServiceHost”而不是“ServiceHost”来使用WCF服务我至少可以通过...我的SearchRequest对象是空的,但我希望能找出原因..

#2


HTTP 404 means that the requested resource was not found. This is most likely being returned from IIS and I would double check the address of the service you are invoking.

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

Since the service itself it up and running I would imagine that there is a typo in the address you are using in your client.

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

#1


ok, i got it...

好,我知道了...

i don't know why, but if i use "WebServiceHost" instead of "ServiceHost" to employ the WCF-Service i can at least get the requests through.. my SearchRequest object is empty, but i hopefully will figure out why..

我不知道为什么,但如果我使用“WebServiceHost”而不是“ServiceHost”来使用WCF服务我至少可以通过...我的SearchRequest对象是空的,但我希望能找出原因..

#2


HTTP 404 means that the requested resource was not found. This is most likely being returned from IIS and I would double check the address of the service you are invoking.

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

Since the service itself it up and running I would imagine that there is a typo in the address you are using in your client.

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