1

Android デバイスから WCF サービスに画像をアップロードしようとしています。小さな画像 (約 20kb) を送信すると、正常に動作します。少し大きい画像 (約 95kb) を送信すると、エラーが発生します。

org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:1 in java.io.InputStreamReader@41636470)

Android コードは次のとおりです。

    byte[] fileContents = IOUtil.readFile(image.getFileName());
    request = new SoapObject(CommonFunctions.NAMESPACE, "SaveAttachment");
    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    new MarshalBase64().register(envelope);
    androidHttpTransport = new HttpTransportSE(CommonFunctions.SERVICE_URL);

    request.addProperty("SomeProperty1", somevalue1);
    request.addProperty("SomeProperty2", somevalue2);
    PropertyInfo p1=new PropertyInfo();
    p1.setName("FileContents");
    p1.setType(MarshalBase64.BYTE_ARRAY_CLASS);
    p1.setValue(fileContents);
    request.addProperty(p1);
    androidHttpTransport.call(CommonFunctions.SOAP_ACTION + "SaveAttachment", envelope);
    int fileId = Integer.parseInt(envelope.getResponse().toString());

数秒後に androidHttpTransport.call 行で例外がスローされます。私の WCF サービスのブレークポイントはヒットしません。WCF バインディングのリクエスト制限を引き上げました。

  <basicHttpBinding>
    <binding name="MobileIntegrationBinding" messageEncoding="Text" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>

KSOAP がプロパティに追加するデータの量に制限はありますか? もしそうなら、これを増やす方法はありますか?

4

2 に答える 2

0

画像を圧縮する必要があります

String imageEncoded;
InputStream is = activity.getContentResolver().openInputStream(uri);
Bitmap img = BitmapFactory.decodeStream(is);
ByteArrayOutputStream convert = new ByteArrayOutputStream();
img.compress(Bitmap.CompressFormat.JPEG, 50, convert);
byte[] b = convert.toByteArray();
imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);

そして、バイトなしのBase64を使用して変換します..アンドロイドでは、約50MBのバイトにのみ変換します

于 2016-04-15T21:49:55.467 に答える
0

あ、やっとわかった。私のバインディングとサービス宣言はすべて web.config で台無しになっていたため、maxReceivedMessageSize などへの変更は効果がありませんでした。これは、サービスがカスタム バインディングを使用する代わりにデフォルト バインディングを使用していたためです。

于 2013-02-04T10:36:40.593 に答える