Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAP web service reference in .NET naming conflict issue

i have a .net issue when im trying to consume SAP ws , the element system cusing this error

  error CS0120: An object reference is required for the nonstatic field, method, or property 'Bapiret2.System'

their is a solution as described here BUT im want to find a solution that doesn't required to change the WSDL

http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2009/04/17/system-namespace-conflict-in-sap-web-services.aspx

or this one , http://ddkonline.blogspot.com/2009/09/sap-to-microsoft-net-integration-fixes.html

do you have any experience with that and how you solve it?

thanks miki

like image 963
MIkCode Avatar asked Oct 27 '11 08:10

MIkCode


2 Answers

Since this issue is caused by naming conflict in .NET and SAP, another workaround for this issue without changing SAP configuration:

Add an alias for System.XML as below in Reference.cs

using SysXml = System.Xml;

Then, replace all the System.Xml where report the error with "SysXml" as below (please note that the word "SysXml" is originally "System.Xml" after adding the service, which caused this issue)

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=SysXml.Schema.XmlSchemaForm.Unqualified)]
public string Type {
    get {
        return this.typeField;

    set {
        this.typeField = value;
    }
}
like image 184
Weifeng Avatar answered Sep 30 '22 07:09

Weifeng


The problem is because System namespace in both Windows and BAPI. This can be dealt with by adding global:: before all calls giving the above errors. This does not involve editing WSDL.

References: Comment on one of the page you mentioned above and link that comment referred to.

like image 35
Harshal Baviskar Avatar answered Sep 30 '22 08:09

Harshal Baviskar