我想通过改造发送一些数据,包括图像和三个字符串, 如果有人可以帮助我,我的WCF服务器端方法签名应如何处理这些发布的数据?
以下代码是我的客户端改装(虽然我不确定它是否写得很好)。
@Multipart
@POST("PostBanderolDataJSON")
Call<MyResponse> PostData(@Part("banderolNr") RequestBody banderolNr, @Part("pharmacy") RequestBody pharmacy, @Part("place") RequestBody place, @Part("report_pic\"; filename=\"rp.png\" ") RequestBody file);
}
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(RetrofitApiInterface.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
RetrofitApiInterface api = retrofit.create(RetrofitApiInterface.class);
RequestBody reportImage = RequestBody.create(MediaType.parse("image/jpeg"), ImagePath);
RequestBody banderoNr = RequestBody.create(MediaType.parse("text/plain"), etBanderolNr.getText().toString());
RequestBody pharmacy = RequestBody.create(MediaType.parse("text/plain"), Pharmacy.getText().toString());
RequestBody place = RequestBody.create(MediaType.parse("text/plain"), Place.getText().toString());
Call<MyResponse> call = api.PostData(banderoNr,pharmacy,place,reportImage);
call.enqueue(new Callback<MyResponse>() {
@Override
public void onResponse(Call<MyResponse> call, Response<MyResponse> response) {
if (response.isSuccessful()) {
if (!response.body().error) {
Toast.makeText(getApplicationContext(), "Data Sent Successfully...", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Some error occurred...", Toast.LENGTH_LONG).show();
}
progress.dismiss();
}
else{
Toast.makeText(getApplicationContext(),"Something went wrong with the request to the server !",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<MyResponse> call, Throwable t) {
progress.dismiss();
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
}
});