0
votes

Why can't I "Add Service Reference" in Visual Studio to this odata endpoint:

<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx" Version="3.0">
    <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="3.0">
       <Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="nsuli_com">
          <EntityType Name="EntityType0">
          <Key>
             <PropertyRef Name="DateS"/>
          </Key>
          <Property Name="DateS" Type="Edm.DateTime" Nullable="false"/>
          </EntityType>
          <EntityContainer Name="us">
             <EntitySet Name="ImportedSeries_NFPDates" EntityType="nsuli_com.EntityType0"/>
          </EntityContainer>
      </Schema>
   </edmx:DataServices>

It works from LINQPad 4 using the driver "WCF Data Services 5.5 (OData 3)"... but "Add Service Reference..." shows the error:

There was an error downloading 'http://nsuli.com/odata/us/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://nsuli.com/odata/us/'.
The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 354 bytes of the response were: '<?xml version="1.0" encoding="utf-8"?><service xml:base="http://nsuli.com/odata/us/" xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom"><workspace><atom:title type="text">Default</atom:title><collection href="ImportedSeries_NFPDates"><atom:title type="text">ImportedSeries_NFPDates</atom:title></collection></workspace></service>'.
If the service is defined in the current solution, try building the solution and adding the service reference again.
2

2 Answers

1
votes

It should be a metadata format issue. the following service can be used to "Add Service Reference". If you can change the service side code, you can use it as demo. http://services.odata.org/V3/OData/OData.svc/$metadata

On the other hand, OData can use T4 to generate client code now. You can refer following blog: http://blogs.msdn.com/b/odatateam/archive/2014/03/11/how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class.aspx

0
votes

If I do

metadata = metadata.Replace(
    "xmlns:edmx=\"schemas.microsoft.com/ado/2009/11/edmx\"",
    "xmlns:edmx=\"schemas.microsoft.com/ado/2007/06/edmx\""
) 

in my $metadata document, then "Add Service Reference" works just fine...........