WCF json REST服务的方法之一返回404,其余方法工作正常

时间:2013-11-12 21:32:04

标签: c# json wcf http rest

我用3种方法创建了一个WCF休息服务,问题是两个方法在visual studio开发服务器上工作正常,但最后一个返回404(当我尝试使用jquery使用服务时,根据到fiddler2,以及尝试使用浏览器访问该方法时。

不工作的方法的服务合同如下:

 [OperationContract]
 [FaultContract(typeof(GeneralCalendarFault))]
 [FaultContract(typeof(ConfigurationFault))]
 [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GeoLocationSearch/{controlIdentification}/{positionX}/{positionY}/{positionZ}/{radiusInMeters}/{maxNumberOfEventsToBeReturned}/{startFetchingFromIndex}")]
 GeoLocationSearch_Response GeoLocationSearch(string controlIdentification, string positionX, string positionY, string positionZ, string radiusInMeters, string maxNumberOfEventsToBeReturned, string startFetchingFromIndex);

两种方法的服务合同如下:

[OperationContract]
[FaultContract(typeof(GeneralCalendarFault))]
[FaultContract(typeof(ConfigurationFault))]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/AdressSearch/{controlIdentification}/{addressSearchString}/{maxNumberOfEventsToBeReturned}/{startFetchingFromIndex}")] 
AddressSearch_Response AdressSearch(string controlIdentification, string addressSearchString, string maxNumberOfEventsToBeReturned, string startFetchingFromIndex);

[OperationContract]
[FaultContract(typeof(GeneralCalendarFault))]
[FaultContract(typeof(ConfigurationFault))]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetAddressSuggest/{controlIdentification}/{search}/{maxNumberOfSuggestsToBeReturned}")]
GetAddressSuggest_Response GetAddressSuggest(string controlIdentification, string search, string maxNumberOfSuggestsToBeReturned);

端点配置如下所示:

<service name="Somenamespace.ServiceRest" behaviorConfiguration="Somenamespace.DevelopmentBehavior">
        <endpoint binding="webHttpBinding" address="json" contract="Somenamespace.IServiceRest" />
        <endpoint binding="mexHttpBinding" address="mex" contract="IMetadataExchange" />
      </service>

....

<webHttpBinding>
        <binding
          name="webHttpBinding"
          allowCookies="false"
          bypassProxyOnLocal="false"
          closeTimeout="00:10:00"
          hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="2147483647"
          maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647"
          openTimeout="00:10:00"

          receiveTimeout="00:10:00"
          sendTimeout="00:10:00"
          transferMode="Buffered"
          useDefaultWebProxy="true"
          >


            <security mode="None">
              <!--<transport clientCredentialType = "Windows"
                    proxyCredentialType="None"
                    realm="hei" />-->
            </security>
            <readerQuotas             
              maxArrayLength="2147483647"            
              maxBytesPerRead="2147483647"            
              maxDepth="2147483647"             
              maxNameTableCharCount="2147483647"                    
              maxStringContentLength="2147483647" />
        </binding>
        <!--proxyAddress="URI"
        writeEncoding="UTF8Encoding"
        -->
      </webHttpBinding>

我无法做任何与GeoLocationSearch方法有所不同的方法,这会导致该方法因未找到404而失败,其余方法完美无缺。

任何帮助都会受到高度赞赏。

修改 这是对有效方法的请求的http标头:

GET http://localhost:52896/ServiceRest.svc/AdressSearch/11111111-1111-1111-1111-111111111111/Mikke%20Mus/10/0?_=1384292586745 HTTP/1.1
Host: localhost:52896
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost:59026/Front.aspx
Origin: http://localhost:59026
Connection: keep-alive

以下是对GeoLocationSearch方法的请求的http标头,结果为404:

GET http://localhost:52896/ServiceRest.svc/GeoLocationSearch/11111111-1111-1111-1111-111111111111/11.495263000000001/64.015019/0/200/10/0?_=1384292586747 HTTP/1.1
Host: localhost:52896
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost:59026/Front.aspx
Origin: http://localhost:59026
Connection: keep-alive

0 个答案:

没有答案