Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OData Connected Service to the project failed: Cannot write to a closed TextWriter #369

Open
softshipper opened this issue Jul 24, 2023 · 5 comments
Assignees

Comments

@softshipper
Copy link

Hi all,

I am trying to use https://github.com/unchase/Unchase.OData.Connectedservice/ to generate OData client C# code based on a metadata file.
The service is hosted on SAP S/4HANA and the metadata is in version 2.0.
Here is the content of the metadata:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0"
    xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
    xmlns:sap="http://www.sap.com/Protocols/SAPData">
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_AGGREGATION',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="Org.OData.Aggregation.V1" Alias="Aggregation"/>
    </edmx:Reference>
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_ANALYTICS',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="com.sap.vocabularies.Analytics.v1" Alias="Analytics"/>
    </edmx:Reference>
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_CAPABILITIES',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="Org.OData.Capabilities.V1" Alias="Capabilities"/>
    </edmx:Reference>
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_CODELIST',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="com.sap.vocabularies.CodeList.v1" Alias="SAP__CodeList"/>
        <edmx:Include Namespace="com.sap.vocabularies.CodeList.v1" Alias="CodeList"/>
    </edmx:Reference>
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_COMMON',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="com.sap.vocabularies.Common.v1" Alias="Common"/>
    </edmx:Reference>
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_COMMUNICATION',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="com.sap.vocabularies.Communication.v1" Alias="Communication"/>
    </edmx:Reference>
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_MEASURES',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="Org.OData.Measures.V1" Alias="Measures"/>
    </edmx:Reference>
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_PERSONALDATA',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="com.sap.vocabularies.PersonalData.v1" Alias="PersonalData"/>
    </edmx:Reference>
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_UI',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="com.sap.vocabularies.UI.v1" Alias="UI"/>
    </edmx:Reference>
    <edmx:Reference Uri="https://sap/opu/odata/iwfnd/catalogservice;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_VALIDATION',Version='0001',SAP__Origin='EM_CORE')/$value"
        xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
        <edmx:Include Namespace="Org.OData.Validation.V1" Alias="Validation"/>
    </edmx:Reference>
    <edmx:DataServices m:DataServiceVersion="2.0">
        <Schema Namespace="API_COMPANYCODE_SRV" xml:lang="en" sap:schema-version="1"
            xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
            <Annotation Term="Core.SchemaVersion" String="1.0.0"
                xmlns="http://docs.oasis-open.org/odata/ns/edm"/>
            <EntityType Name="A_CompanyCodeType" sap:label="Company Code" sap:content-version="1">
                <Key>
                    <PropertyRef Name="CompanyCode"/>
                </Key>
                <Property Name="CompanyCode" Type="Edm.String" Nullable="false" MaxLength="4" sap:display-format="UpperCase" sap:label="Company Code"/>
                <Property Name="CompanyCodeName" Type="Edm.String" MaxLength="25" sap:label="Company Name" sap:quickinfo="Name of Company Code or Company"/>
                <Property Name="CityName" Type="Edm.String" MaxLength="25" sap:label="City"/>
                <Property Name="Country" Type="Edm.String" MaxLength="3" sap:display-format="UpperCase" sap:label="Country/Region Key"/>
                <Property Name="Currency" Type="Edm.String" MaxLength="5" sap:label="Currency" sap:quickinfo="Currency Key" sap:semantics="currency-code"/>
                <Property Name="Language" Type="Edm.String" MaxLength="2" sap:label="Language Key"/>
                <Property Name="ChartOfAccounts" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:label="Chart of Accounts"/>
                <Property Name="FiscalYearVariant" Type="Edm.String" MaxLength="2" sap:display-format="UpperCase" sap:label="Fiscal Year Variant"/>
                <Property Name="Company" Type="Edm.String" MaxLength="6" sap:display-format="UpperCase" sap:label="Company"/>
                <Property Name="CreditControlArea" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:label="Credit control area"/>
                <Property Name="CountryChartOfAccounts" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:label="Alternative COA" sap:quickinfo="Alternative Chart of Accounts"/>
                <Property Name="FinancialManagementArea" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:label="FM Area" sap:quickinfo="Financial Management Area"/>
                <Property Name="AddressID" Type="Edm.String" MaxLength="10" sap:display-format="UpperCase" sap:label="Address"/>
                <Property Name="TaxableEntity" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:label="Taxes on Sls/Purc." sap:quickinfo="Taxes on Sales/Purchases Group"/>
                <Property Name="VATRegistration" Type="Edm.String" MaxLength="20" sap:display-format="UpperCase" sap:label="VAT Registration No." sap:quickinfo="VAT Registration Number"/>
                <Property Name="ExtendedWhldgTaxIsActive" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Extended WTax Active" sap:quickinfo="Indicator: Extended Withholding Tax Active"/>
                <Property Name="ControllingArea" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:label="Controlling Area"/>
                <Property Name="FieldStatusVariant" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:label="Field status variant" sap:quickinfo="Field Status Variant"/>
                <Property Name="NonTaxableTransactionTaxCode" Type="Edm.String" MaxLength="2" sap:display-format="UpperCase" sap:label="Output Tax Code" sap:quickinfo="Output Tax Code for Non-Taxable Transactions"/>
                <Property Name="DocDateIsUsedForTaxDetn" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Tax Determ.with Doc.Date" sap:quickinfo="Indicator: Document Date As the Basis for Tax Determination"/>
                <Property Name="TaxRptgDateIsActive" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Tax Date" sap:quickinfo="Tax Reporting Date Active in Documents"/>
            </EntityType>
            <EntityContainer Name="API_COMPANYCODE_SRV_Entities" m:IsDefaultEntityContainer="true" sap:message-scope-supported="true" sap:supported-formats="atom json xlsx">
                <EntitySet Name="A_CompanyCode" EntityType="API_COMPANYCODE_SRV.A_CompanyCodeType" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:content-version="1"/>
            </EntityContainer>
            <Annotations Target="API_COMPANYCODE_SRV.API_COMPANYCODE_SRV_Entities"
                xmlns="http://docs.oasis-open.org/odata/ns/edm">
                <Annotation Term="Common.ApplyMultiUnitBehaviorForSortingAndFiltering" Bool="true"/>
            </Annotations>
            <Annotations Target="API_COMPANYCODE_SRV.API_COMPANYCODE_SRV_Entities"
                xmlns="http://docs.oasis-open.org/odata/ns/edm">
                <Annotation Term="Capabilities.BatchSupported" Bool="false"/>
            </Annotations>
            <Annotations Target="API_COMPANYCODE_SRV.API_COMPANYCODE_SRV_Entities/A_CompanyCode"
                xmlns="http://docs.oasis-open.org/odata/ns/edm">
                <Annotation Term="Capabilities.ReadRestrictions">
                    <Record>
                        <PropertyValue Property="Description" String="Reads the items of all company codes."/>
                        <PropertyValue Property="LongDescription" String="Reads the company codes available in your system."/>
                        <PropertyValue Property="ReadByKeyRestrictions">
                            <Record>
                                <PropertyValue Property="Description" String="Reads a company code by key."/>
                                <PropertyValue Property="LongDescription" String="Reads a selected company code for the provided company code key."/>
                            </Record>
                        </PropertyValue>
                    </Record>
                </Annotation>
            </Annotations>
            <atom:link rel="self" href="https://sap-s4odata/sap/opu/odata/sap/API_COMPANYCODE_SRV/$metadata"
                xmlns:atom="http://www.w3.org/2005/Atom"/>
            <atom:link rel="latest-version" href="https://sap-s4odata/sap/opu/odata/sap/API_COMPANYCODE_SRV/$metadata"
                xmlns:atom="http://www.w3.org/2005/Atom"/>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

The following steps show how I imported the metadata file:

image
image

As you can see on the last step I have received an error.

I also tried to import https://services.odata.org/V2/Northwind/Northwind.svc/$metadata file and it generated OData client without any error.

Best regards

@brunohdossantos
Copy link

I also have the same error

@austalakov
Copy link

austalakov commented Aug 23, 2023

Same error on a different SAP S/4HANA service. I hoped running through the odata-cli instead of the Visual Studio extension would give some more details but it fails silently.

@henrikcrepido
Copy link

henrikcrepido commented Aug 31, 2023

Had the same issue but was resolved by downloading the schema and removing:
<Annotation Term="Core.SchemaVersion" String="1.0.0" xmlns="http://docs.oasis-open.org/odata/ns/edm"/>

@EricSch
Copy link

EricSch commented Oct 19, 2023

Wow. same here and no answer yet from Microsoft

@henrikcrepido And it didn't help to remove this line

@EricSch
Copy link

EricSch commented Nov 14, 2023

I advise not use this tool, even not anything different from Microsoft.
I opened an official support request at Microsoft.
They didn't provide any help with this issue.

My conclusion:

  1. Don't use the OData Connector
  2. Don't use anything from Microsoft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants