使用Asp.Net Core将参数传递给soap方法SOAPCORE

问题描述 投票:0回答:1

我使用SoapCore开发了肥皂方法。

这是我的代码:

    [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>

但请求参数始终为空。

如果我像这样更改请求,它就会起作用。

我应该怎样做才能解决问题?

c# asp.net xml soap soapcore
1个回答
1
投票

我在使用命名空间时遇到了同样的问题。您正在界面中定义命名空间:

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

但在模型中您将其留空:

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

我不是专家,但从我的经验来看,解串器似乎不知道它应该将对象映射到的类型。对我来说,简单地匹配命名空间就是数据契约解决了问题,在您的用例中它看起来像:

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

希望有帮助

© www.soinside.com 2019 - 2024. All rights reserved.