おはようございます。メモリ カードにある画像を、ユニットから wcf / C# で行った Web サービスに送信する必要があります。C# が会社の要件であったことはあまり知りません。送信することもできますWCF用のStremですが、ビットマップなどに変換して変換するのに問題があります。
wcfで投稿画像を作成するAndroidコードに従ってください:
/**
*
* Método responsável por enviar imagem para o servidor
*
* @param String caminho
* @author Douglas Costa <douglas.cst90@gmail.com.br>
* @since 01/07/2013 18:27:49
* @version 1.0
*/
public static void upload(String caminho){
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.0.205:8070/Service/uploadImagem");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
File file = new File(caminho);
//This is the new shit to deal with MIME
MultipartEntity entity = new MultipartEntity();
entity.addPart("image", new FileBody(file, "image/jpeg"));
httppost.setEntity(entity);
try {
String responseString = httpclient.execute(httppost, responseHandler);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
イメージからストリームを受け取る C# の WCF メソッドに関する私の投稿は次のとおりです。
/// Método POST que recebe um Stream do Android
/// </summary>
/// <param name="imagem"></param>
/// <returns></returns>
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "uploadImagem")]
public Bitmap uploadImagem(Stream imagem)
{
try
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = imagem.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
buffer = ms.ToArray();
}
using (MemoryStream mStream = new MemoryStream())
{
mStream.Write(buffer, 0, buffer.Length);
Bitmap bm = new Bitmap(mStream);
return bm;
}
}
catch (Exception)
{
return null;
}
}
ストリームを変換するいくつかの方法をすでに試しましたが、送信方法が正しいかどうかもわかりませんが、JAVA Web サービスで動作する同様の方法があります。
誰かがC#で私を助けることができれば感謝します.
英語のエラーで申し訳ありません、ありがとう。