使用WCF模板40将文件从Android(2.3.4)上传到WCF 4.0 REST服务

使用WCF模板40将文件从Android(2.3.4)上传到WCF 4.0 REST服务,android,wcf,rest,c#-4.0,wcf-binding,Android,Wcf,Rest,C# 4.0,Wcf Binding,我正在尝试使用下面的代码从Android(2.3.4)上传一个文件,我知道如果我也想发送参数,我必须使用multipart post。这是我的Android代码: public void uploadFile(File uploadFile) { HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost("http://192.168.0.102/applicatio

我正在尝试使用下面的代码从Android(2.3.4)上传一个文件,我知道如果我也想发送参数,我必须使用multipart post。这是我的Android代码:

public void uploadFile(File uploadFile) {
    HttpClient httpClient = new DefaultHttpClient();

    HttpPost postRequest = new HttpPost("http://192.168.0.102/application/services/sendfile/");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();

    // Indicate that this information comes in parts (text and file)
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

try {

    //Create a JSON object to be used in the StringBody
    JSONObject jsonObj = new JSONObject();

    //Add some values
    jsonObj.put("filename", uploadFile.getName());

    //Add the JSON "part"
    reqEntity.addPart("entity", new StringBody(jsonObj.toString()));
}
catch (JSONException e) {
    Log.v("App", e.getMessage());
}
catch (UnsupportedEncodingException e) {
    Log.v("App", e.getMessage());
}

FileBody fileBody = new FileBody(uploadFile);//, "application/octet-stream");
    reqEntity.addPart("file", fileBody);

    try {
        postRequest.setEntity(reqEntity);

         //Execute the request "POST"
    HttpResponse httpResp = httpClient.execute(postRequest);

    //Check the status code, in this case "created"
    if(((HttpResponse) response).getStatusLine().getStatusCode() == HttpStatus.SC_CREATED){
        Log.v("App","Created");
    }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
我的web.config中有这个

  <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            <remove name="WebDAVModule" />
            <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </modules>
        <directoryBrowse enabled="false" />
    </system.webServer>

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <standardEndpoints>
            <webHttpEndpoint>
                <!--
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
            via the attributes on the <standardEndpoint> element below
        -->
                <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
            </webHttpEndpoint>
        </standardEndpoints>
    </system.serviceModel>
如果我在WCF中设置断点,你知道为什么WCF没有收到文件吗

如果有人能提供一个更好的示例,说明如何将文件从Android(2.3.4)发送到WCF 4.0,我们将不胜感激


提前谢谢!Guillermo。

问题在于WCF中的绑定!改变他们使它工作

你能和我们分享你的改变吗?谢谢。-1因为“改变他们让它工作”忽略了他们是如何改变的。
  <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            <remove name="WebDAVModule" />
            <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        </modules>
        <directoryBrowse enabled="false" />
    </system.webServer>

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <standardEndpoints>
            <webHttpEndpoint>
                <!--
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
            via the attributes on the <standardEndpoint> element below
        -->
                <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
            </webHttpEndpoint>
        </standardEndpoints>
    </system.serviceModel>
private void RegisterRoutes()
        {
            RouteTable.Routes.Add(new ServiceRoute("Service", new WebServiceHostFactory(), typeof(AccidentService)));
        }