0

画像をアップロードしようとすると、以下のエラーが発生します。

コンテンツ タイプが 'multipart/form-data;' であるため、メッセージを処理できません。境界=AwQm1pbogJ6qQuZlUZjJ6kNOvbehrlyozA-w」は、予期されたタイプ「text/xml」ではありませんでした。charset=utf-8'.

アンドロイドコード:

HttpPost httppost = new HttpPost("http://192.168.1.111/androidservice/MediaUploadService.svc/uploadFile");
File photo = new File(Environment.getExternalStorageDirectory(), "01.jpg");
MultipartEntity t = new MultipartEntity();
t.addPart("t", new FileBody(photo));
httppost.setEntity(t);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);

WCF コード :

namespace AndroidService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MediaUploadService" in code, svc and config file together.
public class MediaUploadService : IMediaUploadService
{
    public void UploadFile(Stream fileContents)
    {
       byte[] buffer = new byte[10000];
        int bytesRead, totalBytesRead = 0;
        do
        {
            bytesRead = fileContents.Read(buffer, 0, buffer.Length);
            totalBytesRead += bytesRead;
        } while (bytesRead > 0);
        File.WriteAllText(@"D:\\Vechile\log2.txt", totalBytesRead.ToString());
    }
}
}

バインディング:

  <system.serviceModel>
<behaviors>
  <endpointBehaviors>
    <behavior name="httpBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>

  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>

    <behavior name="PublishMetadataBehavior">
      <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
    </behavior>

  </serviceBehaviors>
</behaviors>

<bindings>
  <webHttpBinding>
    <binding name="WebHttpDtreaming" transferMode="Streamed" >
    </binding>
  </webHttpBinding>
</bindings>

<standardEndpoints>
  <webHttpEndpoint>
   <standardEndpoint name=""
                  helpEnabled="true"
                  automaticFormatSelectionEnabled="true"
                  maxReceivedMessageSize="1000000"/>
  </webHttpEndpoint>
</standardEndpoints>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />

助けていただければ幸いです。

4

1 に答える 1

0

このhttppost.setHeader( "content-type"、 "application / json")を試してください

于 2012-12-01T14:02:29.487 に答える