我用 3 种方法创建了一个 WCF 休息服务,问题是其中两种方法在 Visual Studio 开发服务器上工作正常,但最后一个返回 404(根据 fiddler2,当我尝试使用 jquery 使用服务时,以及尝试使用浏览器访问该方法时。
不起作用的方法的服务合同如下所示:
[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