WCF期望找到具有名称的节点类型Element

时间:2016-02-29 13:56:35

标签: c# wcf soap

鉴于此WSDL: Adyen notification WSDL
而这个svcutil命令用来创建相应的C#类:

svcutil.exe https://ca-test.adyen.com/ca/services/Notification?wsdl /t:code /l:c# /o:"C:\NotificationRequest.cs" /ct:System.Collections.Generic.List`1

和OperationContract:

[OperationContract(Action="http://notification.services.adyen.com/sendNotification")]  
string SendNotification(NotificationRequest notificationRequest);

调用SendNotification方法(SOAP)与WCFStorm一起使用 但是当我通过具有测试按钮的第三方网站调用该方法时,我得到:

  

OperationFormatter遇到无效的Message正文。预计会找到名为“SendNotification”的节点类型“Element”和名称空间“http://tempuri.org/”。找到名为“ns1:sendNotification”的节点类型“Element”和名称空间“http://notification.services.adyen.com

这是第三方请求调用的一部分,它给我提出了问题:

<soap:Body><ns1:sendNotification xmlns:ns1="http://notification.services.adyen.com"><ns1:notification>

如何使用,最好是一些小的C#属性指令来解决这个问题?

更新
通过向 IPSPNotificationService ServiceContract添加命名空间修复了“http://tempuri.org/” - 问题的一部分:

[ServiceContract(Namespace = "http://notification.services.adyen.com")]
public interface IPSPNotificationService

更新2
通过更改OperationContract WCFStorm仍然可以正常工作。现在该方法也被第三方调用触发,但在这种情况下,NotificationRequest参数为NULL:

[OperationContract(Action="http://notification.services.adyen.com/sendNotification", Name="sendNotification")]
string SendNotification(NotificationRequest notificationRequest);

更新3
让我们以更简单的方式来看待它。鉴于下面的xml,我需要什么样的合同/服务装饰?

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
    <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
        <EventID>0</EventID>
        <Type>3</Type>
        <SubType Name="Information">0</SubType>
        <Level>8</Level>
        <TimeCreated SystemTime="2016-03-08T10:27:30.7325676Z" />
        <Source Name="System.ServiceModel.MessageLogging" />
        <Correlation ActivityID="{742fac90-3b97-4c9f-aee3-fd2589f75c37}" />
        <Execution ProcessName="obscured" ProcessID="13280" ThreadID="11" />
        <Channel />
        <Computer>obscured</Computer>
    </System>
    <ApplicationData>
        <TraceData>
            <DataItem>
                <MessageLogTraceRecord Time="2016-03-08T11:27:30.7315670+01:00" Source="TransportReceive" Type="System.ServiceModel.Channels.BufferedMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
                    <HttpRequest>
                        <Method>POST</Method>
                        <QueryString/>
                        <WebHeaders>
                            <SOAPAction>"http://notification.services.adyen.com/sendNotification"</SOAPAction>
                            <Content-Length>1140</Content-Length>
                            <Content-Type>text/xml; charset=UTF-8</Content-Type>
                            <Authorization>Basic obscured</Authorization>
                            <Host>obscured</Host>
                            <User-Agent>Jakarta Commons-HttpClient/3.0.1</User-Agent>
                        </WebHeaders>
                    </HttpRequest>
                    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                        <s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
                            <To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">https://obscured</To>
                            <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://notification.services.adyen.com/sendNotification</Action>
                        </s:Header>
                        <soap:Body>
                            <ns1:sendNotification xmlns:ns1="http://notification.services.adyen.com">
                                <ns1:notification>
                                    <live xmlns="http://notification.services.adyen.com">false</live>
                                    <notificationItems xmlns="http://notification.services.adyen.com">
                                        <NotificationRequestItem>
                                            <additionalData xsi:nil="true"/>
                                            <amount>
                                                <currency xmlns="http://common.services.adyen.com">EUR</currency>
                                                <value xmlns="http://common.services.adyen.com">10000</value>
                                            </amount>
                                            <eventCode>AUTHORISATION</eventCode>
                                            <eventDate>2016-03-08T11:27:55.572+01:00</eventDate>
                                            <merchantAccountCode>obscured</merchantAccountCode>
                                            <merchantReference>obscured</merchantReference>
                                            <operations>
                                                <string>REFUND</string>
                                            </operations>
                                            <originalReference xsi:nil="true"/>
                                            <paymentMethod>ideal</paymentMethod>
                                            <pspReference>obscured</pspReference>
                                            <reason/>
                                            <success>true</success>
                                        </NotificationRequestItem>
                                    </notificationItems>
                                </ns1:notification>
                            </ns1:sendNotification>
                        </soap:Body>
                    </soap:Envelope>
                </MessageLogTraceRecord>
            </DataItem>
        </TraceData>
    </ApplicationData>
</E2ETraceEvent>

最终更新
我放弃了,我看到第三方也可以发送JSON帖子。我调整了配置以使用webHttpBinding,将示例JSON转换为datacontract,并从OperationContext.Current.RequestContext.RequestMessage反序列化发布的消息。

0 个答案:

没有答案