Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;无法从SOAP信封中剥离有效负载“;使用ParkSquare.SoapClient_C#_Soap Client - Fatal编程技术网

C# &引用;无法从SOAP信封中剥离有效负载“;使用ParkSquare.SoapClient

C# &引用;无法从SOAP信封中剥离有效负载“;使用ParkSquare.SoapClient,c#,soap-client,C#,Soap Client,我尝试用另一种方法挑战生成的svcUtil SOAP客户端。 虽然svcUtil方法工作得很好,但由于它使用到Saop服务器的持久WCF通道,我们希望尝试避免这种始终连接的行为。另一方面,svcUtil通过从wsdl生成DTO做得很好,因此我们只希望将其用于DTO SparkQuare提供了一个使用标准HttpClient的SoapClient nuget,它符合我们的目标。然而,我很难正确设置它 目前我收到了以下错误: System.AggregateException:发生一个或多个错误。(

我尝试用另一种方法挑战生成的svcUtil SOAP客户端。 虽然svcUtil方法工作得很好,但由于它使用到Saop服务器的持久WCF通道,我们希望尝试避免这种始终连接的行为。另一方面,svcUtil通过从wsdl生成DTO做得很好,因此我们只希望将其用于DTO

SparkQuare提供了一个使用标准HttpClient的SoapClient nuget,它符合我们的目标。然而,我很难正确设置它

目前我收到了以下错误:

System.AggregateException:发生一个或多个错误。(无法从SOAP信封中剥离有效负载) ----ParkSquare.SoapClient.SoapHttpClientException:无法从SOAP信封中剥离负载

我猜我没有正确设置defaultNamespaceaction,但我还没有找到相关文档。有人知道这件事吗

using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using ParkSquare.SoapClient;
using System.Net.Http.Headers;
using System.Text;
using Soap_sern_mvt_ServiceReference; //DTO generated by SvcUtil

namespace ErpApi.EndPoint.ParkSquareSoapClient
{

    public class SerialNumberMouvementParkSquareSoapClient : ISerialNumberMouvement
    {
        private ISoapClient _soapClient;
        private HttpClient _httpClient;

        public SerialNumberMouvementParkSquareSoapClient()
        {
            string cred = "some:credentials";
            _httpClient = new HttpClient();
            _httpClient.DefaultRequestHeaders.Authorization = 
                new AuthenticationHeaderValue(
                    "Basic", 
                    Convert.ToBase64String(Encoding.ASCII.GetBytes(cred)));

            _soapClient = new ParkSquare.SoapClient.SoapClient(
                _httpClient,
                new RawBodySerializer(),
                new SoapHttpRequestBuilder(),
                new PayloadStripper(),
                new BodyDeserializer()); 
        }

        public async Task<IEnumerable<string>> GetAsync(string serialNumber)
        {
            ZsdSernMvtRequest requestDto = new ZsdSernMvtRequest();
            ZsdSernMvt data = new ZsdSernMvt
            {
                EtSernrMvt = new List<ZsdSSernrSalesMvt>().ToArray(),
                IndividualSerialNumber = serialNumber
            };

            requestDto.ZsdSernMvt = data;

            //Exception will fire here :
             var responseDto = await _soapClient.PostAsync<ZsdSernMvtRequest, ZsdSernMvtResponse1>(
                endpoint: new Uri("http://theSoapServer/sap/bc/srt/rfc/sap/zws_sern_mvt/010/zome_sern_mvt/zome_sern_mvt?sap-client=010"),
                request: requestDto,
                 defaultNamespace: "urn:sap-com:document:sap:soap:functions:mc-style",
                action: "urn:sap-com:document:sap:soap:functions:mc-style:ZWS_SERN_MVT:ZsdSernMvtRequest",
                SoapVersion.Soap12);

            return new List<string>() { responseDto.ToString() };
        }
   }
}  
使用系统;
使用System.Net.Http;
使用System.Collections.Generic;
使用System.Threading.Tasks;
使用ParkSquare.SoapClient;
使用System.Net.Http.Header;
使用系统文本;
使用Soap\u sern\u mvt\u serviceference//SvcUtil生成的DTO
命名空间ErpApi.EndPoint.ParkSquareSoapClient
{
公共类SerialNumberMovementParksQuareSoapClient:ISerialNumberMovement
{
私有ISoapClient(soapClient);;
私有httpclientu HttpClient;
public SerialNumberMovementParksQuareSoapClient()
{
string cred=“some:credentials”;
_httpClient=新的httpClient();
_httpClient.DefaultRequestHeaders.Authorization=
新的AuthenticationHeaderValue(
“基本”,
Convert.ToBase64String(Encoding.ASCII.GetBytes(cred));
_soapClient=new ParkSquare.soapClient.soapClient(
_httpClient,
新的RawBodySerializer(),
新的SoapHttpRequestBuilder(),
新的PayloadStripper(),
新的BodyDeserializer());
}
公共异步任务GetAsync(字符串serialNumber)
{
ZsdSernMvtRequest requestDto=新的ZsdSernMvtRequest();
ZsdSernMvt数据=新的ZsdSernMvt
{
EtSernrMvt=新列表().ToArray(),
IndividualSerialNumber=serialNumber
};
requestDto.ZsdSernMvt=数据;
//例外情况将在此处触发:
var responseDto=wait\u soapClient.PostAsync(
端点:新Uri(“http://theSoapServer/sap/bc/srt/rfc/sap/zws_sern_mvt/010/zome_sern_mvt/zome_sern_mvt?sap-客户=010“,
请求:requestDto,
defaultNamespace:“urn:sap com:document:sap:soap:functions:mc-style”,
操作:“urn:sapcom:document:sap:soap:functions:mc-style:ZWS\u-SERN\u-MVT:ZsdSernMvtRequest”,
SoapVersion.Soap12);
返回新列表(){responseDto.ToString()};
}
}
}  
下面是svcutil生成的代码供参考,其中包含上面使用的DTO

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Soap_sern_mvt_ServiceReference
{


    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style", ConfigurationName="Soap_sern_mvt_ServiceReference.ZWS_SERN_MVT")]
    public interface ZWS_SERN_MVT
    {

        [System.ServiceModel.OperationContractAttribute(Action="urn:sap-com:document:sap:soap:functions:mc-style:ZWS_SERN_MVT:ZsdSernMvtRequest", ReplyAction="*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
        System.Threading.Tasks.Task<Soap_sern_mvt_ServiceReference.ZsdSernMvtResponse1> ZsdSernMvtAsync(Soap_sern_mvt_ServiceReference.ZsdSernMvtRequest request);
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:sap-com:document:sap:soap:functions:mc-style")]
    public partial class ZsdSernMvt
    {

        private ZsdSSernrSalesMvt[] etSernrMvtField;

        private string individualSerialNumberField;

        private ZsdSSernr[] multipleSerialNumbersField;

        private string productIsAWatchField;

        /// <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 ZsdSSernrSalesMvt[] EtSernrMvt
        {
            get
            {
                return this.etSernrMvtField;
            }
            set
            {
                this.etSernrMvtField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string IndividualSerialNumber
        {
            get
            {
                return this.individualSerialNumberField;
            }
            set
            {
                this.individualSerialNumberField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        [System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
        public ZsdSSernr[] MultipleSerialNumbers
        {
            get
            {
                return this.multipleSerialNumbersField;
            }
            set
            {
                this.multipleSerialNumbersField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
        public string ProductIsAWatch
        {
            get
            {
                return this.productIsAWatchField;
            }
            set
            {
                this.productIsAWatchField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style")]
    public partial class ZsdSSernrSalesMvt
    {

        private string brand_codeField;

        private string intercompagy_codeField;

        private string serial_numberField;

        private string product_SAP_numberField;

        private string receipt_dateField;

        private string sales_dateField;

        private string customer_numberField;

        private string nameField;

        private string additional_textField;

        private string movement_codeField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string Brand_code
        {
            get
            {
                return this.brand_codeField;
            }
            set
            {
                this.brand_codeField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string Intercompagy_code
        {
            get
            {
                return this.intercompagy_codeField;
            }
            set
            {
                this.intercompagy_codeField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public string Serial_number
        {
            get
            {
                return this.serial_numberField;
            }
            set
            {
                this.serial_numberField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
        public string Product_SAP_number
        {
            get
            {
                return this.product_SAP_numberField;
            }
            set
            {
                this.product_SAP_numberField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
        public string Receipt_date
        {
            get
            {
                return this.receipt_dateField;
            }
            set
            {
                this.receipt_dateField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
        public string Sales_date
        {
            get
            {
                return this.sales_dateField;
            }
            set
            {
                this.sales_dateField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=6)]
        public string Customer_number
        {
            get
            {
                return this.customer_numberField;
            }
            set
            {
                this.customer_numberField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=7)]
        public string Name
        {
            get
            {
                return this.nameField;
            }
            set
            {
                this.nameField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=8)]
        public string Additional_text
        {
            get
            {
                return this.additional_textField;
            }
            set
            {
                this.additional_textField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=9)]
        public string Movement_code
        {
            get
            {
                return this.movement_codeField;
            }
            set
            {
                this.movement_codeField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style")]
    public partial class ZsdSSernr
    {

        private string serial_numberField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string Serial_number
        {
            get
            {
                return this.serial_numberField;
            }
            set
            {
                this.serial_numberField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:sap-com:document:sap:soap:functions:mc-style")]
    public partial class ZsdSernMvtResponse
    {

        private ZsdSSernrSalesMvt[] etSernrMvtField;

        /// <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 ZsdSSernrSalesMvt[] EtSernrMvt
        {
            get
            {
                return this.etSernrMvtField;
            }
            set
            {
                this.etSernrMvtField = value;
            }
        }
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class ZsdSernMvtRequest
    {

        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style", Order=0)]
        public Soap_sern_mvt_ServiceReference.ZsdSernMvt ZsdSernMvt;

        public ZsdSernMvtRequest()
        {
        }

        public ZsdSernMvtRequest(Soap_sern_mvt_ServiceReference.ZsdSernMvt ZsdSernMvt)
        {
            this.ZsdSernMvt = ZsdSernMvt;
        }
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class ZsdSernMvtResponse1
    {

        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="urn:sap-com:document:sap:soap:functions:mc-style", Order=0)]
        public Soap_sern_mvt_ServiceReference.ZsdSernMvtResponse ZsdSernMvtResponse;

        public ZsdSernMvtResponse1()
        {
        }

        public ZsdSernMvtResponse1(Soap_sern_mvt_ServiceReference.ZsdSernMvtResponse ZsdSernMvtResponse)
        {
            this.ZsdSernMvtResponse = ZsdSernMvtResponse;
        }
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
    public interface ZWS_SERN_MVTChannel : Soap_sern_mvt_ServiceReference.ZWS_SERN_MVT, System.ServiceModel.IClientChannel
    {
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
    public partial class ZWS_SERN_MVTClient : System.ServiceModel.ClientBase<Soap_sern_mvt_ServiceReference.ZWS_SERN_MVT>, Soap_sern_mvt_ServiceReference.ZWS_SERN_MVT
    {

        public ZWS_SERN_MVTClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress)
        {
        }

        public System.Threading.Tasks.Task<Soap_sern_mvt_ServiceReference.ZsdSernMvtResponse1> ZsdSernMvtAsync(Soap_sern_mvt_ServiceReference.ZsdSernMvtRequest request)
        {
            return base.Channel.ZsdSernMvtAsync(request);
        }

        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));
        }
    }
}
//------------------------------------------------------------------------------
// 
//这段代码是由一个工具生成的。
//
//对此文件的更改可能会导致不正确的行为,如果
//重新生成代码。
// 
//------------------------------------------------------------------------------
名称空间Soap\u sern\u mvt\u服务引用
{
[System.CodeDom.Compiler.GeneratedCodeAttribute(“Microsoft.Tools.ServiceModel.Svcutil”,“2.0.1”)]
[System.ServiceModel.ServiceContractAttribute(Namespace=“urn:sap com:document:sap:soap:functions:mc style”,ConfigurationName=“soap\u sern\u mvt\u servicerence.ZWS\u sern\u mvt”)]
公共接口ZWS_SERN_MVT
{
[System.ServiceModel.OperationContractAttribute(Action=“urn:sap com:document:sap:soap:functions:mc-style:ZWS\u-SERN\u-MVT:ZsdSernMvtRequest”,ReplyAction=“*”)
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
System.Threading.Tasks.Task ZsdSernMvtAsync(Soap\u sern\u mvt\u serviceference.ZsdSernMvtRequest请求);
}
/// 
[System.CodeDom.Compiler.GeneratedCodeAttribute(“Microsoft.Tools.ServiceModel.Svcutil”,“2.0.1”)]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,Namespace=“urn:sapcom:document:sap:soap:functions:mc-style”)]
公共部分类ZsdSernMvt
{
私有ZsdSSernrSalesMvt[]etSernrMvtField;
私有字符串individualSerialNumberField;
专用ZsdSSernr[]多个序列号字段;
私有字符串productIsAWatchField;
/// 
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified,Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute(“项”,Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable=false)]
公共ZsdSSernrSalesMvt[]EtSernrMvt
{
得到
{
返回此.etSernrMvtField;
}
设置
{
this.etSernrMvtField=值;
}
}
/// 
[System.Xml.Serialization.xmlementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified,Order=1)]
公共字符串IndividualSerialNumber
{
得到
{
返回此.individualSerialNumberField;
}
设置
{
this.individualSerialNumberField=值;
}
}
/// 
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified,Order=2)]
[System.Xml.Serialization.XmlArrayItemAttribute(“项”,Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable=false)]
公共ZsdSSernr[]多个序列号
{