簡體   English   中英

使用 Asp.Net Core 將參數傳遞給 soap 方法 SOAPCORE

[英]Passing parameter to soap method SOAPCORE with Asp.Net Core

我使用 SoapCore 開發了 soap 方法。

這是我的代碼:

    [ServiceContract(Namespace = "http://txn.xxx.com")]
    public interface ISampleService
    {
            [OperationContract()]
        void Reserve(long timestamp, string posId, string employeeRef, string merchantRef, int amountCents, string itemRef, int validitySeconds, long txnId, PayterTokenRequest token, string signature);


    }

    public class SampleService : ISampleService
    {
      public void Reserve(long timestamp, string posId, string employeeRef, string merchantRef, int amountCents, string itemRef, int validitySeconds, long txnId, PayterTokenRequest token, string signature)
        {
            return;
        }


    }

 [DataContract(Name = "token", Namespace = "")]
    public class PayterTokenRequest
    {
       
        [DataMember(Name = "tokenId")]
        [MessageBodyMember(Namespace = "", Order = 0, Name = "tokenId")]
        public string TokenId { get; set; }

      
        [DataMember(Name = "tokenRef")]
        [MessageBodyMember(Namespace = "", Order = 1, Name = "tokenRef")]
        public string TokenRef { get; set; }

     
        [DataMember(Name = "tokenVersion")]
        [MessageBodyMember(Namespace = "", Order = 2, Name = "tokenVersion")]
        public int TokenVersion { get; set; }
    }


他們在文檔中指定了設備將如何發送請求,如下所示。

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:txn="http://txnHost.payter.com">
<soapenv:Header/>
<soapenv:Body>
<txn:reserve soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<timestamp xsi:type="xsd:long">1369231373</timestamp>
<posId xsi:type="xsd:string">posId</posId>
<employeeRef xsi:type="xsd:string">SYSTEM</employeeRef>
<merchantRef xsi:type="xsd:string">merchantRef</merchantRef>
<amountCents xsi:type="xsd:int">1</amountCents>
<currency xsi:type="xsd:string">EUR</currency>
<itemRef xsi:type="xsd:string"/>
<validitySeconds xsi:type="xsd:int">0</validitySeconds>
<token>
<tokenId xsi:type="xsd:string">ac8191d3</tokenId>
<tokenRef xsi:type="xsd:string">d39181acf734ae</tokenRef>
<tokenVersion xsi:type="xsd:int">0</tokenVersion>
</token>
<txnId xsi:type="xsd:long">1</txnId>
<signature xsi:type="xsd:string">548d9db3a066c8b46c5ccafc45f7c230f8d9442c</signature>
</txn:reserve>
</soapenv:Body>
</soapenv:Envelope>

但是請求參數總是 null

在此處輸入圖像描述

在此處輸入圖像描述

如果我像這樣更改請求,它正在工作

在此處輸入圖像描述

在此處輸入圖像描述

我應該怎么做才能解決問題?

謝謝你的幫助。

我在玩命名空間時遇到了同樣的問題。 您正在界面中定義命名空間:

[ServiceContract(Namespace = "http://txn.xxx.com")]
public interface ISampleService

但在 model 中,您將其留空:

[DataContract(Name = "token", Namespace = "")]
public class PayterTokenRequest

我不是專家,但從我的經驗來看,反序列化器似乎不知道它應該是 map object 的類型。 對我來說,簡單地匹配命名空間就是 datacontract 解決了這個問題,在你的用例中看起來像:

[DataContract(Name = "token", Namespace = "http://txn.xxx.com")]
public class PayterTokenRequest

希望能幫助到你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM