gpt4 book ai didi

c# - 返回的 soap 客户端不能破坏响应体 net core 的稳定性

转载 作者:行者123 更新时间:2023-12-04 15:36:57 27 4
gpt4 key购买 nike

我有一个使用 SOAP 服务的 dotnet 应用程序,问题是当我调用该服务时立即返回一个异常,说无法读取结果主体

我尝试通过 SOAP-UI 调用该服务,它运行良好。

下面是为使用 SOAP 客户端而编写的代码。

        var request = new testRequest
{
moduleC = model.ModuleC.ToString(),
moduleT = model.ModuleT.ToString(),
Number = model.Number.ToString(),
};
var response = GetSoapResponse<TestRequest, TestResponse>((p) =>
{
var result = _client.TestMethod(request);
return result;
}, request);


private TResult GetSoapResponse<TParameters, TResult>(Func<TParameters, TResult> callback, TParameters parameters)
{
using (new OperationContextScope(_client.InnerChannel))
{
SetCredentials();
var result = callback.Invoke(parameters);
return result;
}
}

protected void SetCredentials() => OperationContext.Current.OutgoingMessageHeaders.Add(
new UDBSecurityHeader(
Options.Username,
Options.Password));

这是从 VS 为客户端生成的代码:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.8.3752.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sampple.com/test")]
public partial class TestResponse : object, System.ComponentModel.INotifyPropertyChanged {

private TestResponseData dataField;

private string statusCodeField;

private string[] errorsField;

private string isSucceedField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public TestResponseData data {
get {
return this.dataField;
}
set {
this.dataField = value;
this.RaisePropertyChanged("data");
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType="integer", Order=1)]
public string statusCode {
get {
return this.statusCodeField;
}
set {
this.statusCodeField = value;
this.RaisePropertyChanged("statusCode");
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("errors", Order=2)]
public string[] errors {
get {
return this.errorsField;
}
set {
this.errorsField = value;
this.RaisePropertyChanged("errors");
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=3)]
public string isSucceed {
get {
return this.isSucceedField;
}
set {
this.isSucceedField = value;
this.RaisePropertyChanged("isSucceed");
}
}

public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}

public partial class TestResponseData : object, System.ComponentModel.INotifyPropertyChanged {

private long permitSequenceField;

private bool permitSequenceFieldSpecified;

private long sequenceExceptionField;

private bool sequenceExceptionFieldSpecified;

private string statusField;

public long permitSequence {
get {
return this.permitSequenceField;
}
set {
this.permitSequenceField = value;
this.RaisePropertyChanged("permitSequence");
}
}

public bool permitSequenceSpecified {
get {
return this.permitSequenceFieldSpecified;
}
set {
this.permitSequenceFieldSpecified = value;
this.RaisePropertyChanged("permitSequenceSpecified");
}
}

public long sequenceException {
get {
return this.sequenceExceptionField;
}
set {
this.sequenceExceptionField = value;
this.RaisePropertyChanged("sequenceException");
}
}

public bool sequenceExceptionSpecified {
get {
return this.sequenceExceptionFieldSpecified;
}
set {
this.sequenceExceptionFieldSpecified = value;
this.RaisePropertyChanged("sequenceExceptionSpecified");
}
}

public string status {
get {
return this.statusField;
}
set {
this.statusField = value;
this.RaisePropertyChanged("status");
}
}

public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}

预期的 XML 响应必须如下所示:

<tns:TestResponse xmlns:tns="http://www.sampple.com/test">
<tns:data>
<tns:permitSequence>0.0</tns:permitSequence>
<tns:sequenceException>0.0</tns:sequenceException>
<tns:status>0</tns:status>
</tns:data>
<tns:statusCode>200</tns:statusCode>
<tns:errors/>
<tns:isSucceed>true</tns:isSucceed>

最佳答案

从服务返回的数据类型不允许映射到响应,例如,如果您在响应中声明将返回 long 而您返回 decimal它无法从响应中序列化

private long permitSequenceField;

private long sequenceExceptionField;

permitSequenceField 和 sequenceExceptionField 很长,您无法将它们作为 xmlserializer 中的任何其他日期类型接收

希望这能解决您的问题。

关于c# - 返回的 soap 客户端不能破坏响应体 net core 的稳定性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59410398/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com