netwebservice上传图片
Ⅰ 求教C#:WebService: 我想通过Webservice进行图片的传输
这个网上一大把例子,我之前就在项目中做好了,需要的话私聊
Ⅱ android拍照+文字上传到.net或webservice怎么做
法/步骤
1
在eclipse上安装好android开发环境,android调用webservice使用ksoap,本经验使用的是ksoap2-android-assembly-2.6.4-jar-with-dependencies.jar
2
AndroidManifest.xml中需添加相应的权限,例子:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.camera"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.camera.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Ⅲ ASP.NET WebService文件上传,如果调用webservice的用户量超大,并且存在同时调用,并且还是多文件上传的
你好,是这样的,webservice是专用来提供服务的,他可承受的压力取决于两个因素,连接频率(或者是连接数量)和数据量大小。一般来说不是很大的系统的话即使是上传大文件也不会对服务器造成太大压力。 实现分块上传其实并不是为了给服务器减压,它的主要目的是防止文件过大造成ASP页面提交过期,而且通过分块上传可以做一些进度条,改善用户体验。
这里有一个问题你需要注意,如果你用webservice文件上传实际上文件会在服务器中间流转两次,第一次文件流通过表单发送到WEB服务器上,然后你把这些文件在转换成byte[]发送到webservice上。所以所用webservice上传文件的最主要目的是网站资源分布式,即 ASP.net执行代码和静态资源放到不同服务器上,实现用户浏览时页面HTTP请求的多服务器分散。也可以便于以后WEB服务器的扩充。
Ⅳ 我要传一张图片到服客户端怎么用webservice传
string filePath = this.openFileDialog1.FileName;
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
BinaryWriter bw;
byte[] photo = br.ReadBytes((int)fs.Length);
fs = new FileStream("C:\\ok" + ".jpg", FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
bw.Write(photo);
//byte[]转成Base64String
String s_photo = Convert.ToBase64String(photo, System.Base64FormattingOptions.None);
br.Close();
fs.Close();
Ⅳ .net的webservice如何发布
你好,需要在你的Web.conf文件中添加如下代码才可以在别的电脑访问:
==》注意比对你的Config找到添加的位置:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</configuration>
Ⅵ android拍照+文字上传到.net或webservice怎么做
方法/步骤1
在eclipse上安装好android开发环境,android调用webservice使用ksoap,本经验使用的是ksoap2-android-assembly-2.6.4-jar-with-dependencies.jar
2
AndroidManifest.xml中需添加相应的权限,例子:
<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.camera"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9"/>
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permissionandroid:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permissionandroid:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.example.camera.MainActivity"
android:label="@string/app_name">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
3
activity_main.xml文件代码
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="点击启动相机"/>
<Button
android:id="@+id/savePic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="保存图片到服务器"/>
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#999999"/>
</LinearLayout>
4
MainActivity具体代码
packagecom.example.camera;
importjava.io.ByteArrayOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.FileOutputStream;
importjava.io.IOException;
importorg.kobjects.base64.Base64;
importorg.ksoap2.SoapEnvelope;
importorg.ksoap2.serialization.SoapObject;
importorg.ksoap2.serialization.SoapSerializationEnvelope;
importorg.ksoap2.transport.HttpTransportSE;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.graphics.Bitmap;
importandroid.os.Bundle;
importandroid.os.Environment;
importandroid.provider.MediaStore;
importandroid.util.Log;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.ImageView;
importandroid.widget.TextView;
{
TextViewtv=null;
StringfileName="/sdcard/myImage/my.jpg";//图片保存sd地址
Stringnamespace="http://webservice.service.com";//命名空间
Stringurl="http://192.168.200.19:8080/Web/webservices/Portal";//对应的url
StringmethodName="uploadImage";//webservice方法
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.textView);
//启用相机按钮
Buttonbutton=(Button)findViewById(R.id.button);
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
Intentintent=newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,1);
}
});
//保存图片到服务器按钮(通过webservice实现)
ButtonsaveButton=(Button)findViewById(R.id.savePic);
saveButton.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
testUpload();
}
});
}
/**
*拍照完成后,回掉的方法
*/
@Override
protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){
super.onActivityResult(requestCode,resultCode,data);
if(resultCode==Activity.RESULT_OK){
StringsdStatus=Environment.getExternalStorageState();
if(!sdStatus.equals(Environment.MEDIA_MOUNTED)){//检测sd是否可用
Log.v("TestFile",
"SDcardisnotavaiable/writeablerightnow.");
return;
}
Bundlebundle=data.getExtras();
Bitmapbitmap=(Bitmap)bundle.get("data");//获取相机返回的数据,并转换为Bitmap图片格式
FileOutputStreamb=null;
Filefile=newFile("/sdcard/myImage/");
file.mkdirs();//创建文件夹
try{
b=newFileOutputStream(fileName);
bitmap.compress(Bitmap.CompressFormat.JPEG,100,b);//把数据写入文件
}catch(FileNotFoundExceptione){
e.printStackTrace();
}finally{
try{
b.flush();
b.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
((ImageView)findViewById(R.id.imageView)).setImageBitmap(bitmap);//将图片显示在ImageView里
}
}
/**
*图片上传方法
*
*1.把图片信息通过Base64转换成字符串
*2.调用connectWebService方法实现上传
*/
privatevoidtestUpload(){
try{
FileInputStreamfis=newFileInputStream(fileName);
ByteArrayOutputStreambaos=newByteArrayOutputStream();
byte[]buffer=newbyte[1024];
intcount=0;
while((count=fis.read(buffer))>=0){
baos.write(buffer,0,count);
}
StringuploadBuffer=newString(Base64.encode(baos.toByteArray()));//进行Base64编码
connectWebService(uploadBuffer);
Log.i("connectWebService","start");
fis.close();
}catch(Exceptione){
e.printStackTrace();
}
}
/**
*通过webservice实现图片上传
*
*@paramimageBuffer
*/
privatevoidconnectWebService(StringimageBuffer){
//以下就是调用过程了,不明白的话请看相关webservice文档
SoapObjectsoapObject=newSoapObject(namespace,methodName);
soapObject.addProperty("filename","my.jpg");//参数1图片名
soapObject.addProperty("image",imageBuffer);//参数2图片字符串
=newSoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet=false;
envelope.setOutputSoapObject(soapObject);
=newHttpTransportSE(url);
try{
httpTranstation.call(namespace,envelope);
Objectresult=envelope.getResponse();
Log.i("connectWebService",result.toString());
tv.setText(result.toString());
}catch(Exceptione){
e.printStackTrace();
tv.setText(e.getStackTrace().toString());
}
}
}
5
服务端webservice方法(cxf)
publicStringuploadImage(Stringfilename,Stringimage){
FileOutputStreamfos=null;
try{
StringtoDir="D:\work\image";//存储路径
byte[]buffer=newBASE64Decoder().decodeBuffer(image);//对android传过来的图片字符串进行解码
FiledestDir=newFile(toDir);
if(!destDir.exists()){
destDir.mkdir();
}
fos=newFileOutputStream(newFile(destDir,filename));//保存图片
fos.write(buffer);
fos.flush();
fos.close();
return"上传图片成功!"+"图片路径为:"+toDir;
}catch(Exceptione){
e.printStackTrace();
}
return"上传图片失败!";
}
操作步骤
(1)点击“点击启动相机”按钮,回到拍照模式下,拍照完成,回到初始界面,显示刚拍的照片
(2)点击“保存照片到服务器”按钮,通过webservice把照片保存到服务器中,TextView显示保存信息。
Ⅶ 在delPhi中怎么通过webservice上传文件,比较
您好,很高兴能帮助您
把上传的图片进行编码(base64),数据传输到服务器端后再进行解码生成图片
你的采纳是我前进的动力,
记得好评和采纳,答题不易,互相帮助,
Ⅷ android拍照+文字上传到.net或webservice怎么做
<%@ WebHandler Language="C#" Class="uploadHandler" %>
using
System;
using System.Web;
using System.IO;
public class
uploadHandler : IHttpHandler {
public void ProcessRequest
(HttpContext context) {
context.Response.ContentType =
"text/plain";
context.Response.Charset = "utf-8";
string
suser=context.Request.QueryString["puser"]; //页面传过来的用户id
HttpPostedFile file = context.Request.Files["Filedata"];//页面传过来的文件
string uploadPath = HttpContext.Current.Server.MapPath("/upload/pic/idcard")
+ "\\"; //身份证文件夹
string filename = file.FileName;
int
i = filename.LastIndexOf(".");
string fileExt =
filename.Substring(i);
//DateTime datenow = DateTime.Now;
//string datestring = datenow.ToString("yyyyMMdd");
//string
sizestring = file.ContentLength.ToString();
if (file !=
null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
string uploadoripath = uploadPath + suser + fileExt;
file.SaveAs(uploadoripath);//保存
context.Response.Write("http://xxxxxxx/pic/idcard/"+suser + fileExt);
//返回图片地址
//context.Response.Write(@context.Request["folder"].ToString()+datestring +
sizestring + fileExt);
}
else
{
context.Response.Write("0");
}
}
public bool
IsReusable {
get {
return false;
}
}
}
Ⅸ android如何将图片上传到asp.net编写的webservice
利用二进制流来传
asp.net编写web service时候,给个参数byte[],然后把这个byte[]存储成图片。用FileStream就可以。
android在调用时将需要上传的图片转换为byte[]就可以了。