C#java同期クラスの呼び出し
NetConnectionは送信された非同期httpリクエストで、内部はRemotingClientを通じてリモートにアクセスし、私はRemotingClient Copyを来て、同期httpに変更しました.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Net;
using System.IO;
using FluorineFx;
using FluorineFx.IO;
using FluorineFx.AMF3;
using FluorineFx.Exceptions;
using FluorineFx.Messaging.Messages;
using FluorineFx.Messaging.Api;
using FluorineFx.Messaging.Api.Service;
using FluorineFx.Messaging.Rtmp.Event;
using FluorineFx.Messaging.Rtmp.Service;
namespace netcalljava
{
class RemoteService
{
public static Object Call(string endpoint, string destination, string source, string operation, params object[] arguments)
{
Object result = null;
try
{
Uri uri = new Uri("http://localhost:8080/messagebroker/amf");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.ContentType = "application/x-amf";
request.Method = "POST";
AMFMessage amfMessage = new AMFMessage((ushort)ObjectEncoding.AMF3);
RemotingMessage remotingMessage = new RemotingMessage();
remotingMessage.clientId = Guid.NewGuid().ToString("D");
remotingMessage.destination = destination;
remotingMessage.messageId = Guid.NewGuid().ToString("D");
remotingMessage.timestamp = 0;
remotingMessage.timeToLive = 0;
remotingMessage.SetHeader(MessageBase.EndpointHeader, endpoint);
// if (_netConnection.ClientId == null)
remotingMessage.SetHeader(MessageBase.FlexClientIdHeader, "nil");
// else
// remotingMessage.SetHeader(MessageBase.FlexClientIdHeader, _netConnection.ClientId);
//Service stuff
remotingMessage.source = source;
remotingMessage.operation = operation;
remotingMessage.body = arguments;
AMFBody amfBody = new AMFBody(null, null, new object[] { remotingMessage });
amfMessage.AddBody(amfBody);
Stream requestStream = request.GetRequestStream();
AMFSerializer amfSerializer = new AMFSerializer(requestStream);
amfSerializer.WriteMessage(amfMessage);
amfSerializer.Flush();
amfSerializer.Close();
WebResponse webResponse = request.GetResponse();
if (webResponse == null)
{
throw new Exception();
}
Stream responseStream = webResponse.GetResponseStream();
if (responseStream == null)
{
throw new Exception();
}
AMFDeserializer amfDeserializer = new AMFDeserializer(responseStream);
AMFMessage responseMessage = amfDeserializer.ReadAMFMessage();
AMFBody responseBody = responseMessage.GetBodyAt(0);
for (int i = 0; i < responseMessage.HeaderCount; i++)
{
AMFHeader header = responseMessage.GetHeaderAt(i);
//if (header.Name == AMFHeader.RequestPersistentHeader)
// _netConnection.AddHeader(header.Name, header.MustUnderstand, header.Content);
}
Object obj = responseBody.Content;
if (obj is ErrorMessage)
{
throw new Exception();
}
if (obj is AcknowledgeMessage)
{
result = ((AcknowledgeMessage)obj).body;
}
// PendingCall call = new PendingCall(source, operation, arguments);
// RequestData requestData = new RequestData(request, amfMessage, call, callback);
// request.BeginGetRequestStream(new AsyncCallback(this.BeginRequestFlexCall), requestData);
}
catch (Exception ex)
{
throw new Exception("get remote Error");
}
return result;
}
}
}