none
.Net Core2.2引用SAP的SOAP Web Service问题 RRS feed

  • 问题

  • 从SAP中的web service获得的Reference.cs无法按照一般的方式调用,在

    // 从工厂获取具体的调用实例 
                //callClient = factory.CreateChannel();

    这步时报错,提示interface ZFAMS_ABT1N无法序列化,哪位清楚问题请帮忙指导下,非常感谢。

    注:使用SOAP UI可以正常调用该接口。

    Reference.cs代码如下:

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     此代码由工具生成。
    //
    //     对此文件的更改可能导致不正确的行为,并在以下条件下丢失:
    //     代码重新生成。
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    namespace HiP.SAPInterface.WebService
    {
        
        
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1-preview-30310-0943")]
        [System.ServiceModel.ServiceContractAttribute(Namespace="urn:sap-com:document:sap:rfc:functions", ConfigurationName="HiP.SAPInterface.WebService.ZFAMS_ABT1N")]
        public interface ZFAMS_ABT1N
        {
            
            [System.ServiceModel.OperationContractAttribute(Action="urn:sap-com:document:sap:rfc:functions:ZFAMS_ABT1N:ZFAMS_ABT1NRequest", ReplyAction="urn:sap-com:document:sap:rfc:functions:ZFAMS_ABT1N:ZFAMS_ABT1NResponse")]
            [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
            System.Threading.Tasks.Task<HiP.SAPInterface.WebService.ZFAMS_ABT1NResponse1> ZFAMS_ABT1NAsync(HiP.SAPInterface.WebService.ZFAMS_ABT1NRequest request);
        }
        
        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1-preview-30310-0943")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:sap-com:document:sap:rfc:functions")]
        public partial class ZFAMS_ABT1N1
        {
            
            private ZST_ABT1N[] iT_ABT1NField;
            
            /// <remarks/>
            [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
            [System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
            public ZST_ABT1N[] IT_ABT1N
            {
                get
                {
                    return this.iT_ABT1NField;
                }
                set
                {
                    this.iT_ABT1NField = value;
                }
            }
        }
        
        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1-preview-30310-0943")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sap-com:document:sap:rfc:functions")]
        public partial class ZST_ABT1N
        {
            
            private string bUKRS_FField;
            
            private string bUKRS_TField;
            
            private string aNLN1_FField;
            
            private string aNLN2_FField;
            
            private string bUDATField;
            
            private string tASK_IDField;
            
            private string aNLKLField;
            
            private string kOSTLField;
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
            public string BUKRS_F
            {
                get
                {
                    return this.bUKRS_FField;
                }
                set
                {
                    this.bUKRS_FField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
            public string BUKRS_T
            {
                get
                {
                    return this.bUKRS_TField;
                }
                set
                {
                    this.bUKRS_TField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
            public string ANLN1_F
            {
                get
                {
                    return this.aNLN1_FField;
                }
                set
                {
                    this.aNLN1_FField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
            public string ANLN2_F
            {
                get
                {
                    return this.aNLN2_FField;
                }
                set
                {
                    this.aNLN2_FField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
            public string BUDAT
            {
                get
                {
                    return this.bUDATField;
                }
                set
                {
                    this.bUDATField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
            public string TASK_ID
            {
                get
                {
                    return this.tASK_IDField;
                }
                set
                {
                    this.tASK_IDField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=6)]
            public string ANLKL
            {
                get
                {
                    return this.aNLKLField;
                }
                set
                {
                    this.aNLKLField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=7)]
            public string KOSTL
            {
                get
                {
                    return this.kOSTLField;
                }
                set
                {
                    this.kOSTLField = value;
                }
            }
        }
        
        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1-preview-30310-0943")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sap-com:document:sap:rfc:functions")]
        public partial class ZST_ABT1N_RETURN
        {
            
            private string zGUIDField;
            
            private string aNLN1_TField;
            
            private string aNLN2_TField;
            
            private string bELNS_FField;
            
            private string bELNS_TField;
            
            private string mTYPE_BAPIField;
            
            private string mESSAGE_BAPIField;
            
            private string mTYPE_ZField;
            
            private string mESSAGE_ZField;
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
            public string ZGUID
            {
                get
                {
                    return this.zGUIDField;
                }
                set
                {
                    this.zGUIDField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
            public string ANLN1_T
            {
                get
                {
                    return this.aNLN1_TField;
                }
                set
                {
                    this.aNLN1_TField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
            public string ANLN2_T
            {
                get
                {
                    return this.aNLN2_TField;
                }
                set
                {
                    this.aNLN2_TField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
            public string BELNS_F
            {
                get
                {
                    return this.bELNS_FField;
                }
                set
                {
                    this.bELNS_FField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
            public string BELNS_T
            {
                get
                {
                    return this.bELNS_TField;
                }
                set
                {
                    this.bELNS_TField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
            public string MTYPE_BAPI
            {
                get
                {
                    return this.mTYPE_BAPIField;
                }
                set
                {
                    this.mTYPE_BAPIField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=6)]
            public string MESSAGE_BAPI
            {
                get
                {
                    return this.mESSAGE_BAPIField;
                }
                set
                {
                    this.mESSAGE_BAPIField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=7)]
            public string MTYPE_Z
            {
                get
                {
                    return this.mTYPE_ZField;
                }
                set
                {
                    this.mTYPE_ZField = value;
                }
            }
            
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=8)]
            public string MESSAGE_Z
            {
                get
                {
                    return this.mESSAGE_ZField;
                }
                set
                {
                    this.mESSAGE_ZField = value;
                }
            }
        }
        
        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1-preview-30310-0943")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:sap-com:document:sap:rfc:functions")]
        public partial class ZFAMS_ABT1NResponse
        {
            
            private ZST_ABT1N_RETURN[] eT_RETURNField;
            
            /// <remarks/>
            [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
            [System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
            public ZST_ABT1N_RETURN[] ET_RETURN
            {
                get
                {
                    return this.eT_RETURNField;
                }
                set
                {
                    this.eT_RETURNField = value;
                }
            }
        }
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1-preview-30310-0943")]
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
        public partial class ZFAMS_ABT1NRequest
        {
            
            [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:rfc:functions", Order=0)]
            public HiP.SAPInterface.WebService.ZFAMS_ABT1N ZFAMS_ABT1N;
            
            public ZFAMS_ABT1NRequest()
            {
            }
            
            public ZFAMS_ABT1NRequest(HiP.SAPInterface.WebService.ZFAMS_ABT1N ZFAMS_ABT1N)
            {
                this.ZFAMS_ABT1N = ZFAMS_ABT1N;
            }
        }
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1-preview-30310-0943")]
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
        public partial class ZFAMS_ABT1NResponse1
        {
            
            [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:rfc:functions", Order=0)]
            public HiP.SAPInterface.WebService.ZFAMS_ABT1NResponse ZFAMS_ABT1NResponse;
            
            public ZFAMS_ABT1NResponse1()
            {
            }
            
            public ZFAMS_ABT1NResponse1(HiP.SAPInterface.WebService.ZFAMS_ABT1NResponse ZFAMS_ABT1NResponse)
            {
                this.ZFAMS_ABT1NResponse = ZFAMS_ABT1NResponse;
            }
        }
        
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1-preview-30310-0943")]
        public interface ZFAMS_ABT1NChannel : HiP.SAPInterface.WebService.ZFAMS_ABT1N, System.ServiceModel.IClientChannel
        {
        }
        
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1-preview-30310-0943")]
        public partial class ZFAMS_ABT1NClient : System.ServiceModel.ClientBase<HiP.SAPInterface.WebService.ZFAMS_ABT1N>, HiP.SAPInterface.WebService.ZFAMS_ABT1N
        {
            
            public ZFAMS_ABT1NClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                    base(binding, remoteAddress)
            {
            }
            
            [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
            System.Threading.Tasks.Task<HiP.SAPInterface.WebService.ZFAMS_ABT1NResponse1> HiP.SAPInterface.WebService.ZFAMS_ABT1N.ZFAMS_ABT1NAsync(HiP.SAPInterface.WebService.ZFAMS_ABT1NRequest request)
            {
                return base.Channel.ZFAMS_ABT1NAsync(request);
            }
            
            public System.Threading.Tasks.Task<HiP.SAPInterface.WebService.ZFAMS_ABT1NResponse1> ZFAMS_ABT1NAsync(HiP.SAPInterface.WebService.ZFAMS_ABT1N ZFAMS_ABT1N)
            {
                HiP.SAPInterface.WebService.ZFAMS_ABT1NRequest inValue = new HiP.SAPInterface.WebService.ZFAMS_ABT1NRequest();
                inValue.ZFAMS_ABT1N = ZFAMS_ABT1N;
                return ((HiP.SAPInterface.WebService.ZFAMS_ABT1N)(this)).ZFAMS_ABT1NAsync(inValue);
            }
            
            public virtual System.Threading.Tasks.Task OpenAsync()
            {
                return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
            }
            
            public virtual System.Threading.Tasks.Task CloseAsync()
            {
                return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
            }
        }
    }
    

    2019年4月10日 0:28

答案

  • 这些已经都参照了,没能正确解决问题。

    我自己已经搞定。

    主要的问题有:

    1、Core生成的是异步方法,貌似SAP中不支持其中部分功能(提示传入参数无法识别),所以需使用Framework的方式引用或者使用Svcutil工具从wsdl中生成cs文件。注:svcutil无法传递用户名密码,所以需针对wsdl文件获取。

    2、默认生成的文件中会有个类和接口名称一样,需要修复掉。另外还有部分引用重复命名空间问题,也需修复。

    将修复的cs文件纳入Core项目引用即可。


    <audio controls="controls" style="display:none;"></audio>
    2019年4月14日 3:35

全部回复


  • Hi   wang,binbin,

    请参考下面博客:

    .NET Core 如何调用 WebService

    .net core 引用 webservice 服务


    Best Regards

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年4月11日 7:12
    版主
  • 这些已经都参照了,没能正确解决问题。

    我自己已经搞定。

    主要的问题有:

    1、Core生成的是异步方法,貌似SAP中不支持其中部分功能(提示传入参数无法识别),所以需使用Framework的方式引用或者使用Svcutil工具从wsdl中生成cs文件。注:svcutil无法传递用户名密码,所以需针对wsdl文件获取。

    2、默认生成的文件中会有个类和接口名称一样,需要修复掉。另外还有部分引用重复命名空间问题,也需修复。

    将修复的cs文件纳入Core项目引用即可。


    <audio controls="controls" style="display:none;"></audio>
    2019年4月14日 3:35