我正在尝试上传通过Android手机录制的视频。但是当将视频作为byte[]发送到服务器时,出现以下错误:
01-20 13:03:18.250: E/SaveMedia-response(4393): java.net.SocketException: sendto failed: EPIPE (Broken pipe)
以下是我试图上传视频的步骤:
SoapObject request = new SoapObject(
HelpMeConstant.WSDL_TARGET_NAMESPACE, "SaveMedia");
Log.i("SaveMedia-parameter", "Email : " + Email + ", Media : " + Media
+ "MediaType : " + MediaType + ",MediaExt : " + MediaExt);
MediaAvidance mediainfo = new MediaAvidance();
mediainfo.EmailId = Email;
mediainfo.Media = Media;
mediainfo.MediaExt = MediaExt;
mediainfo.MediaType = MediaType;
PropertyInfo pi = new PropertyInfo();
pi.setName("mediainfo");
pi.setValue(mediainfo);
pi.setType(mediainfo.getClass());
request.addProperty(pi);
/* request.addProperty("EmailId",Email);
request.addProperty("Media", Media);
request.addProperty("MediaType", MediaType);
request.addProperty("MediaExtn", MediaExt);
*/
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
Log.i("SaveMedia","Serialising..");
new MarshalBase64().register(envelope);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(
HelpMeConstant.SOAP_ADDRESS);
Object response = null;
try {
Log.i("SaveMedia","Calling service..");
httpTransport.call(HelpMeConstant.SOAP_ACTION + "SaveMedia",
envelope);
Log.i("SaveMedia","getting response..");
response = envelope.getResponse();
} catch (Exception exception) {
response = exception.toString();
}
Log.i("response", response.toString());
return response.toString();
并且它正在发送到一个 .net web 服务,如下所示:
[WebMethod]
public string SaveMedia(MediaAvidance avidanceinfo)
{
rs = new ResultSet();
rs = logictask.SaveMedia(avidanceinfo.EmailId,avidanceinfo.Media,avidanceinfo.MediaType,avidanceinfo.MediaExt);
return rs.isSuccessfull;
}
媒体存储:
public class MediaAvidance implements KvmSerializable {
public String EmailId;
public byte[] Media;
public String MediaType;
public String MediaExt;
public MediaAvidance() {
}
public MediaAvidance(String EmailID, byte[] Media, String MediaType,
String MediaExt) {
this.EmailId = EmailID;
this.Media = Media;
this.MediaType = MediaType;
this.MediaExt = MediaExt;
}
@Override
public Object getProperty(int arg0) {
switch (arg0) {
case GETEMAILID:
return EmailId;
case GETMEDIA:
return Media;
case GETMEDIATYPE:
return MediaType;
case GETMEDIAEXT:
return MediaExt;
default:
return null;
}
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 4;
}
@SuppressWarnings("rawtypes")
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch (index) {
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "EmailId";
break;
case 1:
info.type = PropertyInfo.OBJECT_CLASS;
info.name = "Media";
break;
case 2:
info.type = PropertyInfo.STRING_CLASS;
info.name = "MediaType";
break;
case 3:
info.type = PropertyInfo.STRING_CLASS;
info.name = "MediaExt";
break;
default:
break;
}
}
@Override
public void setProperty(int index, Object value) {
switch (index) {
case 0:
EmailId = value.toString();
break;
case 1:
Media = (byte[]) value;
break;
case 2:
MediaType = value.toString();
break;
case 3:
MediaExt = value.toString();
break;
default:
break;
}
}
}
在服务器端,MediaAvidance
类没有实现KvmSerializable
及其方法。
我搜索了几天,在stackoverflow上看了很多问题,并了解到我正在尝试在连接关闭时编写代码,这与套接字编程有关。但是,我不知道如何保持连接活动(可能是一个解决方案)。请帮助我。
谢谢, Sourabh
01-20 17:35:40.579: E/SaveDocument-response(13412): SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request. ---> Method HelpMe.SaveMedia can not be reflected. ---> The XML element 'SaveMedia' from namespace 'http://tempuri.org/' references a method and a type. Change the method's message name using WebMethodAttribute or change the type's root element using the XmlRootAttribute.' faultactor: 'null' detail: org.kxml2.kdom.Node@41df97b0
。 - sourabh gupta