"Unable to strip payload from SOAP envelope"使用ParkSquare.SoapClient



我尝试用替代方法挑战生成的svcUtil SOAP Client。 尽管 svcUtil 方法运行良好,但由于它使用到 Saop 服务器的持久 WCF 通道,我们希望尝试避免这种始终连接的行为。另一方面,svcUtil 通过从 wsdl 生成 DTO 做得很好,所以我们只想将其用于 DTO。

SparkQuare提供了一个SoapClient nuget,它使用标准的HttpClient,然后符合我们的目标。但是,我无法正确设置它。

目前我收到此错误:

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

我的猜测是我没有正确设置defaultNamespace操作,但我还没有找到相关文档。有人对此有提示吗?

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() };
}
}
}  

下面供参考的是 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 请求?您可以通过运行 Fiddler(或类似(来捕获请求来获取此请求。

相关内容

  • 没有找到相关文章

最新更新