如何从webservices中获取webservices数据中的数据?

时间:2018-05-29 02:22:17

标签: c# asp.net web-services webmethod

我有一个Web服务,它返回字节作为XML数据的一部分。我将带有“DoPost”方法的字节数据传递给另一个Web服务地址以返回XML格式。但是从第二个Web服务开始,我不知道如何在它通过时获得价值。

using (FileStream fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open))
{
    XmlSerializer xmlSerializer = new XmlSerializer(typeof(EPCISDocumentType));
    ObjectEventType objectEventType = new ObjectEventType();
    EPCISDocumentType epcisDoc = new EPCISDocumentType();
    epcisDoc = (EPCISDocumentType)xmlSerializer.Deserialize(fileStream);

    objectEventType.epcList = epcList.ToArray();
    objectEventType.eventTime = DateTime.Now;
    objectEventType.eventTimeZoneOffset = DateTime.Now.ToString("zzz");
    ReadPointType readPointType = new ReadPointType();
    readPointType.id = locationMasterItems.ReadPoint;
    objectEventType.readPoint = readPointType;
    BusinessLocationType businessLocationType = new BusinessLocationType();
    businessLocationType.id = locationMasterItems.BusinessLocation;
    objectEventType.bizLocation = businessLocationType;

    epcisDoc.EPCISBody = new EPCISBodyType();
    epcisDoc.EPCISBody.EventList = new object[1];
    epcisDoc.EPCISBody.EventList[0] = objectEventType;

    byte[] bsRequest = EpcSerializer.ToEPCISDocumentTypeBytes(epcisDoc);
    HttpCli client = new HttpCli();
    client.Open("http://localhost:5003/WebService.asmx/Getdata");
    client.DoPost(bsRequest, "text/xml; charset=utf-8", null, 60000);

    if (client.StatusCode != HttpStatusCode.OK)
    {
        throw new Exception("error " + client.StatusCode + " ");
    }
}

和webservices 2

[WebMethod]
public void Getdata() {
    string HostURI = "http://localhost:49227/RFIDWebService.asmx";
    getByte(HostURI);
}

[WebMethod]
private byte[] getByte(string URL) 
{
    string s;
    HttpWebRequest wrGETURL = (HttpWebRequest)WebRequest.Create(URL); 
    System.Net.HttpWebResponse webresponse = (HttpWebResponse)wrGETURL.GetResponse();
    wrGETURL.Method = "GET";
    wrGETURL.ContentType = "text/xml; encoding='utf-8'";
    string ct = webresponse.ContentType;
    Stream objStream = webresponse.GetResponseStream();

    BinaryReader breader = new BinaryReader(objStream); 
    byte[] buffer = breader .ReadBytes((int)webresponse.ContentLength);
    using (var ms = new MemoryStream(buffer))
    using (var reader = new StreamReader(ms))
    {
        s = reader.ReadToEnd();
    }
    return buffer; 
}

如何从webservice到webservice 2获取数据变量“bsRequest”并将bsRequest返回给XML?

0 个答案:

没有答案
相关问题