English 中文(简体)
SOAP 未居住的答复物体
原标题:SOAP Response object not populated

I m 要求第三方通过网络解决方案提供AXIS网络服务

通过WSDL案(服务地点已经拆除,因为使用有限)向我的VS项目增加了服务参考。

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
    name="PremiumCharging"
    targetNamespace="http://premiumcharging.verisign.com"
    xmlns:pmg="http://types.premiumcharging.verisign.com"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://premiumcharging.verisign.com"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:types>
    <xsd:schema
        targetNamespace="http://types.premiumcharging.verisign.com"
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:pmg="http://types.premiumcharging.verisign.com"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:complexType name="UserInfo">
        <xsd:sequence>
          <xsd:element name="aggregatorId" type="xsd:int"/>
          <xsd:element name="pwd" type="xsd:string"/>
          <xsd:element name="version" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="StatusInfo">
        <xsd:sequence>
          <xsd:element name="errorCode" type="xsd:int"/>
          <xsd:element name="errorDescription" type="xsd:string"/>
          <xsd:element name="transactionId" type="xsd:int"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="chargeSubscriberResponse">
    <wsdl:part name="chargeSubscriberReturn" type="pmg:StatusInfo"/>
  </wsdl:message>
  <wsdl:message name="chargeSubscriberRequest">
    <wsdl:part name="user" type="pmg:UserInfo"/>
    <wsdl:part name="mdn" type="xsd:string"/>
    <wsdl:part name="productId" type="xsd:string"/>
    <wsdl:part name="shortCode" type="xsd:string"/>
    <wsdl:part name="carrierId" type="xsd:int"/>
    <wsdl:part name="chargeId" type="xsd:string"/>
    <wsdl:part name="msgtxid" type="xsd:string"/>
  </wsdl:message>
  <wsdl:portType name="PremiumChargingPortType">
    <wsdl:operation name="chargeSubscriber">
      <wsdl:input message="tns:chargeSubscriberRequest"/>
      <wsdl:output message="tns:chargeSubscriberResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="PremiumChargingBinding" type="tns:PremiumChargingPortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="chargeSubscriber">
      <soap:operation/>
      <wsdl:input>
        <soap:body parts="user mdn productId shortCode carrierId chargeId msgtxid" use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body parts="chargeSubscriberReturn" use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="PremiumCharging">
    <wsdl:port binding="tns:PremiumChargingBinding" name="PremiumChargingPort">
      <soap:address location="...location removed..."/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

我能够提出请求并收到答复(通过Fiddler获得),但实际反应物体(状态类型)是在叫作“托管人”后制造的,但价值为零(不动产)和空洞(为扼制财产)。

This is an example of the response XML captured in Fiddler:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <chargeSubscriberResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <chargeSubscriberReturn href="#id0"/>
    </chargeSubscriberResponse>
    <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:StatusInfo" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://types.premiumcharging.verisign.com">
      <errorCode href="#id1"/>
      <errorDescription xsi:type="soapenc:string">Non-Carrier MIN</errorDescription>
      <transactionId href="#id2"/>
    </multiRef>
    <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">2216</multiRef>
    <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">-105</multiRef>
  </soapenv:Body>
</soapenv:Envelope>

I have read that certain namespace and naming reference mismatch could be an issue, but I m unable to locate which. Any help is appreciated.

最佳回答

我得以通过创建客户信息检查员来操纵这一对策。

How to Get around WCFs Lack of a preview

Together with @SixtoSeaz suggested SO Answer:

SO Answer

在客户信息检查员的“接收”方法中,I通过在提及多个参考项目的每个节点上分配内分Xml,改变了SOAP的反应。 然后,“身份信息”反应物体确实获得了按需要分列的正确数值。

Behavior and ClientMessageInspector:

public class MyBehavior :  IEndpointBehavior
{
    public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
    {
    }

    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {
        clientRuntime.MessageInspectors.Add(new MyMessageInspector());
    }

    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
    }

    public void Validate(ServiceEndpoint endpoint)
    {
    }
}

public class MyMessageInspector : IClientMessageInspector
{
    public void AfterReceiveReply(ref Message reply, object correlationState)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(reply.ToString());

        List<XmlElement> items = new List<XmlElement>();
        Dictionary<string, XmlElement> multiRefs = new Dictionary<string,XmlElement>();

        InspectNodes(doc.DocumentElement, items, multiRefs);

        FixNodes(items, multiRefs);

        MemoryStream ms = new MemoryStream();

        XmlWriter writer = XmlWriter.Create(ms);
        doc.WriteTo(writer);
        writer.Flush();
        ms.Position = 0;

        XmlReader reader = XmlReader.Create(ms);
        reply = Message.CreateMessage(reader, int.MaxValue, reply.Version);
    }

    public object BeforeSendRequest(ref Message request, IClientChannel channel)
    {
        return null;
    }

    private static void InspectNodes(XmlElement element, List<XmlElement> items, Dictionary<string, XmlElement> multiRefs)
    {
        string val = element.GetAttribute("href");
        if (val != null && val.StartsWith("#id"))
            items.Add(element);
        else if (element.Name == "multiRef")
            multiRefs[element.GetAttribute("id")] = element;

        foreach (XmlNode node in element.ChildNodes)
        {
            XmlElement child = node as XmlElement;
            if (child != null)
                InspectNodes(child, items, multiRefs);
        }

    }


    private static void FixNodes(List<XmlElement> items, Dictionary<string, XmlElement> multiRefs)
    {
        // Reverse order so populate the id refs into one single element. This is only a solution in relation to the WSDL definition.
        for (int x = items.Count - 1; x >= 0; x--)
        {
            XmlElement element = items[x];

            string href = element.GetAttribute("href");
            if (String.IsNullOrEmpty(href))
                continue;

            if (href.StartsWith("#"))
                href = href.Remove(0, 1);

            XmlElement multiRef = multiRefs[href];

            if (multiRef == null)
                continue;

            element.RemoveAttribute("href");
            element.InnerXml = multiRef.InnerXml;

            multiRef.ParentNode.RemoveChild(multiRef as XmlNode);
        }
    }

}

And then assign the Behavior to the EndPoint (Service Reference is PMGReference)

MyBehavior behavior = new MyBehavior();
PMGReference.PremiumChargingPortTypeClient client = new PMGReference.PremiumChargingPortTypeClient();
client.Endpoint.Behaviors.Add(behavior);
问题回答

The XML schema definition:

  <xsd:complexType name="StatusInfo">
    <xsd:sequence>
      <xsd:element name="errorCode" type="xsd:int"/>
      <xsd:element name="errorDescription" type="xsd:string"/>
      <xsd:element name="transactionId" type="xsd:int"/>
    </xsd:sequence>
  </xsd:complexType>

• 制作XML,研究(以及世界儿童论坛所期望的内容):

  <StatusInfo>
      <errorCode>-105</errorCode>
      <errorDescription>Non-Carrier MIN</errorDescription>
      <transactionId>2216</transactionId>
  </StatusInfo>

java服务公司正在创建XML,它使用WCF序列器所理解的Rhref/multiref的公约奶制品。 查阅form post,以了解如果你能够改变服务配置,如何避免此类编码。 另一种选择是,采用生成的服务数据合同,并按以下方式手工修改:。 缩略语





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签