使用改型Android消费WCF时,响应主体为空,响应代码为405

使用改型Android消费WCF时,响应主体为空,响应代码为405,android,json,wcf,retrofit,Android,Json,Wcf,Retrofit,我有包含此方法的WCF服务: [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetListInvititionFiltered?StartPage={StartPage}&userID={userID}

我有包含此方法的WCF服务:

[OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Bare,
        UriTemplate = "GetListInvititionFiltered?StartPage={StartPage}&userID={userID}&subject={subject}&customerName={customerName}&country={country}&invitationType={invitationType}&productGroup={productGroup}&companyGroup={companyGroup}&marketingEngineer={marketingEngineer}&proposalEngineer={proposalEngineer}&fromDate={fromDate}&toDate={toDate}&closingDate={closingDate}&sDataSourse={sDataSourse}&sCatalog={sCatalog}")]
    string GetListInvititionFiltered(string StartPage, string userID, string subject, string customerName, string country, string invitationType,
        string productGroup, string companyGroup, string marketingEngineer, string proposalEngineer, string fromDate, string toDate, string closingDate, string sDataSourse, string sCatalog);
当我从浏览器调用此方法时:

localhost:8080/AndroidWCFRestfull/AAPRestFullHttp.svc/GetListInvititionFiltered?StartPage=3&userID=104&subject=&customerName=&country=&invitationType=&productGroup=&companyGroup=&marketingEngineer=&proposalEngineer=&fromDate=01%2f02%2f2017&toDate=01%2f02%2f2017&closingDate=&sDataSourse=DB01-SRV&sCatalog=AAP
它在浏览器中返回此JSON:

"{\"invitationContainer\":{\"PagesCount\":\"3\",\"ListInvititionEntity\":[{\"Co_name\":\"UMM AL QURA CEMENT COMPANY\",\"In_invitation_id\":\"118680\",\"Has_document\":0,\"In_date\":\"1\/2\/2017 9:41:00 AM\",\"ClientName\":\"UMM AL QURA CEMENT COMPANY\",\"Type\":\"E\",\"ProductGroup\":\"LAB AND EDUCATION\",\"Subject\":\"Handheld Precise Colorimeter\",\"Stage\":\"NOT REGISTERED\",\"Countvalue\":0,\"BranchName\":\"Saudi Arabia\",\"IsSeen\":0,\"DocumentPath_Mobile\":\"\",\"DocumentName\":\"\",\"DocumentID\":0},{\"Co_name\":\"GULF CEMENT COMPANY\",\"In_invitation_id\":\"119690\",\"Has_document\":1,\"In_date\":\"1\/2\/2017 2:36:00 PM\",\"ClientName\":\"GULF CEMENT COMPANY\",\"Type\":\"E\",\"ProductGroup\":\"INSTRUMENTATION\",\"Subject\":\"HERMO COUPLE FTBIDT\",\"Stage\":\"NWO\",\"Countvalue\":0,\"BranchName\":\"UAE\",\"IsSeen\":0,\"DocumentPath_Mobile\":\"Invitation Documents\\\\UAE17-8-99-7-200D525136424CB4B8AD0EC6FB6E96FD.msg\",\"DocumentName\":\"NEW ENQUIRY---1000015936---THERMO COUPLE---SE16-739ALG05\",\"DocumentID\":75411},{\"Co_name\":\"KING HUSSEIN CANCER CENTER\",\"In_invitation_id\":\"118674\",\"Has_document\":1,\"In_date\":\"1\/2\/2017 9:20:00 AM\",\"ClientName\":\"KING HUSSEIN CANCER CENTER\",\"Type\":\"T\",\"ProductGroup\":\"LAB AND EDUCATION\",\"Subject\":\"lab miscellaneous supplies\",\"Stage\":\"NOT REGISTERED\",\"Countvalue\":0,\"BranchName\":\"JORDAN\",\"IsSeen\":0,\"DocumentPath_Mobile\":\"Invitation Documents\\\\JOT17-1-99-1-8DFFF7EF2771462B9E0A2F8516ED155E.pdf\",\"DocumentName\":\"14525\",\"DocumentID\":74400},{\"Co_name\":\"CITY CEMENT COMPANY\",\"In_invitation_id\":\"119687\",\"Has_document\":1,\"In_date\":\"1\/2\/2017 2:28:00 PM\",\"ClientName\":\"CITY CEMENT COMPANY\",\"Type\":\"E\",\"ProductGroup\":\"MATERIAL\",\"Subject\":\"Hardox Plate\",\"Stage\":\"NWO\",\"Countvalue\":0,\"BranchName\":\"Saudi Arabia\",\"IsSeen\":0,\"DocumentPath_Mobile\":\"Invitation Documents\\\\SAE17-5-99-5-B7CBAF310C0C4113806C0E139EAE9D9A.msg\",\"DocumentName\":\"FW  16 00896\",\"DocumentID\":75408},{\"Co_name\":\"TECTON LIMITED\",\"In_invitation_id\":\"118679\",\"Has_document\":1,\"In_date\":\"1\/2\/2017 9:38:00 AM\",\"ClientName\":\"TECTON LIMITED\",\"Type\":\"E\",\"ProductGroup\":\"FLOW\",\"Subject\":\"Upgrading of Mina Pumping Station at Silaa - Pumps\",\"Stage\":\"NOT REGISTERED\",\"Countvalue\":0,\"BranchName\":\"UAE\",\"IsSeen\":0,\"DocumentPath_Mobile\":\"Invitation Documents\\\\UAE17-1-99-1-73A1537833314E849804306E9542E422.msg\",\"DocumentName\":\"NEW ENQUIRY    Our Ref   SP17-001SVT99 (TECTON ENGINEERING \\u0026 CONSTRUCTION LLC SUPPLY OF PUMPS  )    \",\"DocumentID\":74405},{\"Co_name\":\"JORDAN BROMINE COMPANY\",\"In_invitation_id\":\"118676\",\"Has_document\":1,\"In_date\":\"1\/2\/2017 9:27:00 AM\",\"ClientName\":\"JORDAN BROMINE COMPANY\",\"Type\":\"E\",\"ProductGroup\":\"POWER TRANSMISSION EQUIPMENT\",\"Subject\":\"SUPPLY OF MOTOR \\u0026 GEAR BOX\",\"Stage\":\"NOT REGISTERED\",\"Countvalue\":0,\"BranchName\":\"JORDAN\",\"IsSeen\":0,\"DocumentPath_Mobile\":\"Invitation Documents\\\\JOE17-1-99-1-E7B5369AA747433AB0900E4748E94289.msg\",\"DocumentName\":\"FW  Rotary feeder inquiry\",\"DocumentID\":74398},{\"Co_name\":\"SALINE WATER CONVERSION CORPORATION\",\"In_invitation_id\":\"119678\",\"Has_document\":1,\"In_date\":\"1\/2\/2017 11:33:00 AM\",\"ClientName\":\"SALINE WATER CONVERSION CORPORATION\",\"Type\":\"E\",\"ProductGroup\":\"MATERIAL\",\"Subject\":\"SUPPLY OF WIRE\",\"Stage\":\"NWO\",\"Countvalue\":0,\"BranchName\":\"Saudi Arabia\",\"IsSeen\":0,\"DocumentPath_Mobile\":\"Invitation Documents\\\\SAE17-4-99-4-388BF4357F254111B80F8F3D43E4560A.msg\",\"DocumentName\":\"FW  RFQ # 1831992\",\"DocumentID\":75400}]}}"
我正在尝试使用改型从Android应用程序读取此JSON,以下是服务方法的接口:

public interface AAPRestfulEndPointInterface {

@POST("GetListInvititionFiltered")
Call<InvitationsContainer> GetListInvititionFiltered(@Query("StartPage") String StartPage,
                                                     @Query("userID") String userID,
                                                     @Query("subject") String subject,
                                                     @Query("customerName") String customerName,
                                                     @Query("country") String country,
                                                     @Query("invitationType") String invitationType,
                                                     @Query("productGroup") String productGroup,
                                                     @Query("companyGroup") String companyGroup,
                                                     @Query("marketingEngineer") String marketingEngineer,
                                                     @Query("proposalEngineer") String proposalEngineer,
                                                     @Query("fromDate") String fromDate,
                                                     @Query("toDate") String toDate,
                                                     @Query("closingDate") String closingDate,
                                                     @Query("sDataSourse") String sDataSourse,
                                                     @Query("sCatalog") String sCatalog);
公共接口{
@POST(“GetListInvitionFiltered”)
调用getListInvitionFiltered(@Query(“StartPage”)字符串StartPage,
@查询(“userID”)字符串userID,
@查询(“主题”)字符串主题,
@查询(“customerName”)字符串customerName,
@查询(“国家”)字符串国家,
@查询(“邀请类型”)字符串邀请类型,
@查询(“productGroup”)字符串productGroup,
@查询(“companyGroup”)字符串companyGroup,
@查询(“marketingEngineer”)字符串marketingEngineer,
@查询(“proposalEngineer”)字符串proposalEngineer,
@查询(“fromDate”)字符串fromDate,
@查询(“toDate”)字符串toDate,
@查询(“closingDate”)字符串closingDate,
@查询(“sdatasource”)字符串sdatasource,
@查询(“sCatalog”)字符串sCatalog);
这是服务的代码调用:

Gson gson = new GsonBuilder()
            .setDateFormat("MM-dd-yyyy")
            .create();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build();

    AAPRestfulEndPointInterface service = retrofit.create(AAPRestfulEndPointInterface.class);


    final Call<InvitationsContainer> apiCall = service.GetListInvititionFiltered("1", "104", "", "", "", "", "", "", "", "", "01/01/2017","01/02/2017", "", "DB01-SRV", "AAP");

    String url = apiCall.request().url().toString();
    Log.i("RETROFIT", url);

    apiCall.enqueue(new Callback<InvitationsContainer>() {
        @Override
        public void onResponse(Call<InvitationsContainer> call, Response<InvitationsContainer> response) {

            Log.i("RETROFIT", "onResponse Called");
            InvitationsContainer result = response.body();

        }

        @Override
        public void onFailure(Call<InvitationsContainer> call, Throwable t) {

            Toast.makeText(MainActivity.this, "Service Call Failure \n" + t.getMessage(), Toast.LENGTH_LONG).show();
            Log.e("RETROFIT", t.getMessage());

        }
    });
Gson Gson=new GsonBuilder()
.setDateFormat(“MM dd yyyy”)
.create();
改装改装=新改装.Builder()
.baseUrl(基本URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
AAPRestfulEndPointInterface服务=改型.create(AAPRestfulEndPointInterface.class);
最终调用apiCall=service.getListInvitiionFiltered(“1”、“104”、“”、“”、“”、“”、“”、“”、“”、“”、“”、“2017年1月1日”、“2017年2月1日”、“DB01-SRV”、“AAP”);
字符串url=apiCall.request().url().toString();
Log.i(“改造”,url);
enqueue(新的回调函数(){
@凌驾
公共void onResponse(调用、响应){
Log.i(“改装”、“调用响应”);
invitationContainer结果=response.body();
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Toast.makeText(MainActivity.this,“服务调用失败\n”+t.getMessage(),Toast.LENGTH\u LONG.show();
Log.e(“改装”,t.getMessage());
}
});
响应对象返回空主体和错误代码405的问题,有人能帮我解决吗

以下是我的回答:

响应{protocol=http/1.1,code=405,message=methodnotallowed,url=}


您的WCF服务只接受
GET
请求。但是
AAPRestfulEndPointInterface
中的
getListInvitionFiltered
方法声明为
POST

@POST("GetListInvititionFiltered")
Call<InvitationsContainer> GetListInvititionFiltered(..);

@POST(“/GetListInvititionFiltered”)在您的intarface中使用反斜杠。我会检查它,但我将反斜杠放在baseURL@Sorathiya Payal中
@GET("GetListInvititionFiltered")
Call<InvitationsContainer> GetListInvititionFiltered(..);