0

I created the following endpoint in my WCF application, that is successfully working (for get calls at least) via GET calls:

    [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);

This is running locally on http://localhost/DigitalREST/XosSearch.svc, as well on our production service. The GET query using the URI template works perfectly fine in a browser, and http://localhost/DigitalREST/XosSearch.svc?wsdl appears to give the correct meta data.

I then went into my web application, added http://localhost/DigitalREST/XosSearch.svc?wsdl as a service reference. I then wrote the following code to interact with the service:

        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();

When the service.Search() method gets called, the following exception occurs:

There was no endpoint listening at http://localhost/DigitalREST/XosSearch.svc?wsdl that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

The inner exception is:

The remote server returned an error: (404) Not Found.

Even if I take out the ?wsdl part, I'm still getting this error. What am I doing wrong?


Here's the IndexArticles contract as requested:
    [OperationContract]
    [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "IndexArticles/{platform}/{portalId}")]
    void IndexArticles(string platform, string portalId);
KallDrexx
  • 27,229
  • 33
  • 143
  • 254

3 Answers3

2

Create a WebHttpBinding instead link. If you cannot find the class, make sure that you have System.ServiceModel.Web referenced

WebHttpBinding binding = new WebHttpBinding()

The current binding, BasicHttpBinding, that you are using is trying to communicate through soap.

Tung
  • 5,334
  • 1
  • 34
  • 41
  • See the answer to this [thread](http://stackoverflow.com/questions/4759672/wcf-changing-clientcredentials-produces-manual-addressing-is-enabled-on-this-f). Notice the `` defined in the endpoint behavior. Make sure that your binding is pointing to a behavior with this value – Tung Mar 07 '12 at 15:09
  • yeah I figured that out right before you posted it. However this still doesn't work as it says "Operation 'IndexArticles' of contract 'IXosSearch' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped."` even though all of my methods in `IXosSearch` all have `BodyStyle = WebMessageBodyStyle.Wrapped`. – KallDrexx Mar 07 '12 at 15:15
  • Can you please post IndexArticles, as defined in your IXosSearch? – Tung Mar 07 '12 at 15:23
  • I was able to get around this based on http://stackoverflow.com/questions/4346554/wcf-service-proxy-throws-exception-when-more-than-one-parameter-is-used-in-oper/4347005#4347005 but that causes the original error (404) to come up again – KallDrexx Mar 07 '12 at 15:32
  • This worked for me `[WebGet(BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "IndexArticles/{platform}/{portalId}")]` . Make sure you change it both on the IContract and the generated code. To be quite honest, making the change in reference.cs is not good (actually, modifying generated code is never good because it gets wiped out). This [developer](http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/7f8a4ec6-7141-4c58-a6a1-bbc9528009b3/) found a lesser evil, but it still requires manual labor - I've verified that it works – Tung Mar 07 '12 at 17:17
  • I ended up giving up and just doing a GET request and deserializing the Json. – KallDrexx Mar 07 '12 at 18:30
0

I have had problems like this before, what I did was save everything, shut Visual Studio down and then reopen it while running it as an administrator (right click and select run as administrator), give that a try perhaps.

Ebikeneser
  • 2,582
  • 13
  • 57
  • 111
  • I already do this, since I commonly need VS to attach to IIS for debugging. So it's always running as admin. – KallDrexx Mar 07 '12 at 14:43
0

It would be benificial to see your endpoint configurations, but it could be a number of different things.

  • Have you got a metadata enpoint?
  • Have you added a service behaviour for metadata?
  • Have you added that behaviour configuration to your service?
ldgorman
  • 1,553
  • 1
  • 14
  • 39