Я создал следующую конечную точку в своем приложении WCF, которая успешно работает (по крайней мере, для вызовов get) через вызовы GET:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "Search/{platform}/{searchedContentTypeList}/?query={query}&requestedFacetGroupCountList={requestedFacetGroupCountList}&searchedFacetList={searchedFacetList}"
+ "&start={start}&limit={limit}&endpoint={endpoint}&portalId={portalId}&resultMetaIncludeList={resultMetaIncludeList}")]
XosSearchResults Search(string query, string platform, string requestedFacetGroupCountList, string searchedFacetList, string searchedContentTypeList,
int start, int limit, string endpoint, string portalId, string resultMetaIncludeList);
Это работает локально на http://localhost/DigitalREST/XosSearch.svc
, а также на нашем производственном сервисе. Запрос GET с использованием шаблона URI отлично работает в браузере, и http://localhost/DigitalREST/XosSearch.svc?wsdl
, похоже, дает правильные метаданные.
Затем я зашел в свое веб-приложение и добавил http://localhost/DigitalREST/XosSearch.svc?wsdl
в качестве ссылки на службу. Затем я написал следующий код для взаимодействия со службой:
var binding = new BasicHttpBinding();
var endpointAddr = new EndpointAddress("http://localhost/DigitalREST/XosSearch.svc?wsdl");
var service = new XosSearchService.XosSearchClient(binding, endpointAddr);
service.Open();
// Run the search
StartIndex = PageSize * SearchPageNum;
SearchResults = service.Search(SearchQuery, Platform, null, FacetSearchString, Constants.VideoContentType, StartIndex, PageSize, Endpoint, PortalId, null);
// Fill generic properties for outside reading
StartIndex = (int)SearchResults.StartIndex;
PageSize = SearchResults.PageSize;
TotalResults = (int)SearchResults.TotalResults;
service.Close();
При вызове метода service.Search()
возникает следующее исключение:
Не было ни одной конечной точки, прослушивающей http://localhost/DigitalREST/XosSearch.svc?wsdl, которая могла бы принять сообщение. Это часто вызвано неверным адресом или действием SOAP. Дополнительные сведения см. в разделе InnerException, если он присутствует.
Внутреннее исключение:
Удаленный сервер вернул ошибку: (404) Not Found.
Даже если я уберу часть ?wsdl
, я все равно получаю эту ошибку. Что я делаю неправильно?
Вот контракт
IndexArticles
по запросу:
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "IndexArticles/{platform}/{portalId}")]
void IndexArticles(string platform, string portalId);