2012-04-19 8 views
0

画像をアップロードしようとしているときに、以下のエラーが表示されます。AndroidからWCFサービスを使用して画像をアップロード:コンテンツタイプのため処理できません

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

のAndroidコード:

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" /> 

私は助けていただきありがとうございます。

+0

を試してみてください? –

答えて

0

は、あなたが私たちあなたのIMediaUploadService示しすることができ、この httppost.setHeader( "コンテンツタイプ"、 "アプリケーション/ JSON")

関連する問題