views:

406

answers:

1

Hi,

I'm having a couple of issues which may be related, or may not. I noticed that when I use Add Service Reference in Visual Studio to add a reference to my data service, the reference.cs it generates does not compile. It complains about a missing namespace. I can fix it up to compile, but this happens every time I update the reference, and it's worrying on other levels too, such as "will this cause other issues".

I also noticed that when I do this, my host server (a console application hosting the data service) logs this:

An exception occurred [System.Data.Services.DataServiceException] :: The URL 
representing the root of the service only supports GET requests.

This is the service config:

  <service behaviorConfiguration="behaviour" name="StatsPlus.Server.HostedServices.SPDataServiceHost">
    <endpoint address="svc" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8752/DataService/"/&gt;
      </baseAddresses>
    </host>
  </service>

And the behaviour:

    <behavior name="behaviour">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="10"/>
    </behavior>

When I try to run svcutil http://localhost:8752/DataService/, I get this:

HTTP GET Error  
URI: http://localhost:8752/DataService
There was an error downloading 'http://localhost:8752/DataService'.  
The request failed with HTTP status 405: Method Not Allowed.  

Any ideas? Much appreciated

Thanks

+2  A: 

I think you're connecting to a wrong address. You have a base address

<add baseAddress="http://localhost:8752/DataService/"/&gt;

and on top of that a relative endpoint address

<endpoint address="svc" binding="webHttpBinding" 

so your complete URL will be the combination of the two:

http://localhost:8752/DataService/svc

Did you try to connect there??

I am not sure if you can have a "mex" metadata exchange endpoint with WCF REST services, really. I was under the impression that the client-side proxy for a WCF Data Service gets its metadata over a special URL call from the HTTP endpoint. So maybe try to remove that from your config as well (and you can't use svcutil on that service, I believe - svcutil is only for SOAP service calls, if I'm not mistaken).

Also, since you're using webHttpBinding and self-hosting, you need to add the webHttp behavior:

<behavior name="behaviour">
  <serviceMetadata httpGetEnabled="true"/>
  <serviceDebug includeExceptionDetailInFaults="true"/>
  <dataContractSerializer maxItemsInObjectGraph="10"/>
  <webHttp />
</behavior>

If you do these two steps, I think you should be able to get at your WCF Data Service. Try it and let us know!

marc_s
Hi,What you're describing is much more similar to my previous config file, so I've gone back to that. The reason I added mex is because I was getting this exception trace in my server log:`[Error] [StatsPlus.Common.Logger ] An exception occurred` `[System.Data.Services.DataServiceException] :: Resource not found``for the segment 'mex'.`I get this when I try to add a service reference. Actually, I think what might be happening here is the Add Service Reference box is trying multiple URIs, and one of them includes /mex.
JohnL
I've added the webhttp endpoint behaviour but I'm not seeing any difference.One other thing which I'm not sure about is that I also have a "normal" WCF service (using [ServiceContract]) in the same process. I'm wondering if this "error" is actually ok - the Add Service Reference seems to just be trying a bunch of URI variants until one works, and the code it's generating is fine with some editing. I'm going to try some basic tests and see if it actually works :)
JohnL