Retrofit实现请求WebService 看这篇就够了。

先看这篇文章:
http://www.vogella.com/tutorials/Retrofit/article.html
再看这篇文章:
http://www.jianshu.com/p/6e4e53d8efe8?winzoom=1

需要注意的几个地方就是

1 在你的接口处 需要设置soapAction
比如

interface Api{
@Headers({
            "Content-Type: text/xml",
            "SOAPAction: http://tempuri.org/GetPlayFileInfo" //一般这里是需要调用的方法名
    })
    @POST("BsSchoolWebService.asmx")
    Call<GetPlayFileInfoRootBean> GetPlayFileInfo(@Body GetPlayFileInfoBean getPlayFileInfoBean);
}

2 在你需要传递参数的对象上需要设置 NamespaceList 比如

@Root(name = "soap:Envelope", strict = false)
@NamespaceList({
        @Namespace(reference = "http://www.w3.org/2001/XMLSchema-instance", prefix = "xsi"),
        @Namespace(reference = "http://www.w3.org/2001/XMLSchema", prefix = "xsd"),
        @Namespace(reference = "http://schemas.xmlsoap.org/soap/envelope/", prefix = "soap")
})
public class GetPlayFileInfoBean {
    @Element(name = "GetPlayFileInfo")
    @Path("soap:Body")
    private GetPlayFileInfoBeanChild GetPlayFileInfochildl;

    public GetPlayFileInfoBeanChild getGetPlayFileInfochildl() {
        return GetPlayFileInfochildl;
    }

    public void setGetPlayFileInfochildl(GetPlayFileInfoBeanChild getPlayFileInfochildl) {
        GetPlayFileInfochildl = getPlayFileInfochildl;
    }
}

其他操作参考上面2个链接就可以了。哈哈。 有问题留言。

猜你喜欢

转载自blog.csdn.net/xiaxiayige/article/details/75108138