不支持WCF服务操作类型

时间:2019-02-23 14:24:25

标签: c# wcf wcftestclient

我用2个异步操作创建了WCF服务。 WCFTestClient返回错误:

  

WCF测试客户端不支持该操作,因为它使用类型SendCreditTransferRequest。

我不知道ProcessingFault操作是否有效,而另一个(SendCreditTransferRequest)为什么无效。

我的.svc代码:

namespace SimulatorServices
{
    public class RealTimePortType : IRealTimePortType
    {
        public void SendCreditTransferRequest(SendCreditTransferRequest request)
        {
            throw new NotImplementedException();
        }

        public void ProcessingFault(ProcessingFault1 request)
        {
            throw new NotImplementedException();
        }
    }
}

我的.svc.cs代码:

namespace SimulatorServices
{
    [ServiceContract]
    public interface IRealTimePortType
    {
        [System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action = "http://realtime247.eu/realtime247/SendCreditTransferRequest")]
        [System.ServiceModel.XmlSerializerFormatAttribute()]
        void SendCreditTransferRequest(SendCreditTransferRequest request);

        [System.ServiceModel.OperationContractAttribute(IsOneWay = true, Action = "http://realtime247.eu/realtime247/ProcessingFault")]
        [System.ServiceModel.XmlSerializerFormatAttribute()]
        void ProcessingFault(ProcessingFault1 request);
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    [System.ServiceModel.MessageContractAttribute(IsWrapped = false)]
    [KnownType(typeof(TransactionHeader))]
    [KnownType(typeof(Document))]
    public partial class SendCreditTransferRequest
    {
        [System.ServiceModel.MessageHeaderAttribute(Namespace = "urn:eu:nets:realtime247:ri.2015.10.14")]
        public TransactionHeader TransactionHeader;
        [System.ServiceModel.MessageBodyMemberAttribute(Name = "SendCreditTransferRequest", Namespace = "urn:eu:nets:realtime247:ri.2015.10.14", Order = 0)]
        public Document SendCreditTransferRequest1;
        public SendCreditTransferRequest()
        {
        }
        public SendCreditTransferRequest(TransactionHeader TransactionHeader, Document SendCreditTransferRequest1)
        {
            this.TransactionHeader = TransactionHeader;
            this.SendCreditTransferRequest1 = SendCreditTransferRequest1;
        }
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    [System.ServiceModel.MessageContractAttribute(IsWrapped = false)]
    [KnownType(typeof(TransactionHeader))]
    [KnownType(typeof(ProcessingFault))]
    public partial class ProcessingFault1
    {
        [System.ServiceModel.MessageHeaderAttribute(Namespace = "urn:eu:nets:realtime247:ri.2015.10.14")]
        public TransactionHeader TransactionHeader;
        [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "urn:eu:nets:realtime247:ri.2015.10.14", Order = 0)]
        public ProcessingFault ProcessingFault;
        public ProcessingFault1()
        {
        }
        public ProcessingFault1(TransactionHeader TransactionHeader, ProcessingFault ProcessingFault)
        {
            this.TransactionHeader = TransactionHeader;
            this.ProcessingFault = ProcessingFault;
        }
    }
}

对不起,但是我没有复制我创建的所有类...

1 个答案:

答案 0 :(得分:0)

我在没有类声明的情况下测试了我的操作,并且这些都可以正常工作。因此,我逐步测试了SendCreditTransferRequest的子类,并找到了问题的根源。 我使用AccountIdentification4Choice中的SendCreditTransferRequest子类,它是pacs.008.001.02(它是ISO20022)xsd中的选择对象。

<xs:complexType name="AccountIdentification4Choice">
  <xs:sequence>
    <xs:choice>
      <xs:element name="IBAN" type="IBAN2007Identifier"/>
      <xs:element name="Othr" type="GenericAccountIdentification1"/>
    </xs:choice>
  </xs:sequence>
</xs:complexType>

我是这样定义的:

[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:iso:std:iso:20022:tech:xsd:pacs.008.001.02")]
public partial class AccountIdentification4Choice
{
    private object itemField;
    [System.Xml.Serialization.XmlElementAttribute("IBAN", typeof(string), Order = 0)]
    [System.Xml.Serialization.XmlElementAttribute("Othr", typeof(GenericAccountIdentification1), Order = 0)]
    public object Item
    {
        get
        {
            return this.itemField;
        }
        set
        {
            this.itemField = value;
        }
    }
}

但是失败。 因此,新问题是,如何在WCF服务中声明选择对象?