开发者

Consume xml data via C# Web Service

开发者 https://www.devze.com 2022-12-19 19:20 出处:网络
I will need to be able to receive this xml data from a Java WebService and I am not really sure what to expose in my WebMethod so I can consume it? It is just a basic order and items. In .Net I would

I will need to be able to receive this xml data from a Java WebService and I am not really sure what to expose in my WebMethod so I can consume it? It is just a basic order and items. In .Net I would just have passed an order object List.

I should expand a bit further. It is an Oracle BPEL process that will need to map to this exposed C# WebService. I would need to expose the OrderNumber, ItemNumber ,etc (as shown in XML). The issue I am having is that I would have 1 to Many items ,etc so I can't just expose the basic items (string, int).

Probably pretty trivial for most the community here...just not sure how to do it? Any suggestions greatly appreciated.

I could do something like (build an order object and it appears to show the xml as I would expect?)

[WebMethod]
public static List<Orders> GetOrders(List<Orders> ordersList)
{
  List<Orders oList = ordersList;

  return oList;
}

XML:

<Order>
  <OrderNumber>12345</OrderNumber>
  <OrderDate>01/25/2010</OrderDate>
  <OrderSource>Affiliate123</OrderSource>
 开发者_如何学运维 <Items>
     <ItemNumber>123478</ItemNumber>
     <Qty>5</Qty>
     <UOM>EA</UOM>
     <Description>Test Item</Description>
  </Items>
 </Order>


You have answered your own question. The .NET web services framework will map a return type of List<T> to a sequence of T at the SOAP level, just as if you had used a T[] (array of T).

When I write up a quick sample service just like yours, this is the XML it returns:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetOrdersResponse xmlns="http://tempuri.org/">
      <GetOrdersResult>
        <Order>
          <OrderNumber>int</OrderNumber>
          <OrderDate>dateTime</OrderDate>
          <OrderSource>string</OrderSource>
          <Items>
            <Item xsi:nil="true" />
            <Item xsi:nil="true" />
          </Items>
        </Order>
        <Order>
          <OrderNumber>int</OrderNumber>
          <OrderDate>dateTime</OrderDate>
          <OrderSource>string</OrderSource>
          <Items>
            <Item xsi:nil="true" />
            <Item xsi:nil="true" />
          </Items>
        </Order>
      </GetOrdersResult>
    </GetOrdersResponse>
  </soap:Body>
</soap:Envelope>

Your BPEL layer should be able to consume that pretty easily.


You don't need to expose a WebMethod, as I am assuming you are not publishing a WebService, instead you are consuming someone else's WebService.

I am not sure if I understand your question correctly, but if I do then in Visual Studio you just have to "Add Webreference" to the WebService URL and it should automatically create the .NET proxy objects, you can then use these objects to consume the methods.

Cheers, Mithun

http://blog.mithunbose.com

0

精彩评论

暂无评论...
验证码 换一张
取 消