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

前端之家收集整理的这篇文章主要介绍了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个链接就可以了。哈哈。 有问题留言。

猜你在找的WebService相关文章