consuming xml webservice using retrofit Parameter `soap12:Body` does not have a match in class

Android Studio 3.4

I am testing the HolidayService2 endpoint and I want to consume that endpoint using retrofit.

This is the request endpoint:

POST /HolidayService_v2/HolidayService2.asmx HTTP/1.1
Host: www.holidaywebservice.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetCountriesAvailable xmlns="http://www.holidaywebservice.com/HolidayService_v2/" />
  </soap12:Body>

and the response endpoint:

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetCountriesAvailableResponse xmlns="http://www.holidaywebservice.com/HolidayService_v2/">
      <GetCountriesAvailableResult>
        <CountryCode />
        <CountryCode />
      </GetCountriesAvailableResult>
    </GetCountriesAvailableResponse>
  </soap12:Body>
</soap12:Envelope>

The classes I have created for the request is:

@Root(name = "Envelope")
@NamespaceList(value = [
    Namespace(prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance"),
    Namespace(prefix = "xsd", reference = "http://www.w3.org/2001/XMLSchema"),
    Namespace(prefix = "soap12", reference = "http://www.w3.org/2003/05/soap-envelope")
])
data class CountriesAvailableRequestEnvelope(
    @Element(name = "Body", required = false) val countriesAvailableRequest: CountriesAvailableRequest)

@Root(name = "GetCountriesAvailable", strict = false)
@NamespaceList(value = [
Namespace(reference = "http://www.holidaywebservice.com"),
Namespace(reference="http://www.w3.org/2003/05/soap-envelope")])
data class CountriesAvailableRequest(
    @Element(name = "GetCountriesAvailable", required = false) val code: String)

And for the response classes I have done the following:

@Root(name = "Envelope")
@NamespaceList(value = [
    Namespace(prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance"),
    Namespace(prefix = "xsd", reference = " http://www.w3.org/2001/XMLSchema"),
    Namespace(prefix = "soap12", reference = "http://www.w3.org/2003/05/soap-envelope")])
data class CountriesAvailableResponseEnvelope(
    @Element(required = false, name = "Body") val countryCode: CountryCode)

@Root(name = "Body", strict = false)
@Namespace(reference="http://www.w3.org/2003/05/soap-envelope")
data class CountryCode(
    @Element(name = "description", required = false) val description: String?,
    @Element(name = "code", required = false) val code: String?)

This is the first time I am consuming web service and parsing xml. However, I am not sure if my classes I have setup reflect the xml.

This is my endpoint:

interface WebServices {
    @Headers("Content-Type: text/xml")
    @POST("/HolidayService_v2/HolidayService2.asmx")
    fun getAvailableCountries(@Body countriesAvailableRequest: CountriesAvailableRequestEnvelope): Observable<CountriesAvailableResponseEnvelope>
}

For calling the endpoint using rxJava:

fun requestFromWebService() {    webServices.getAvailableCountries(CountriesAvailableRequestEnvelope(CountriesAvailableRequest("UK")))
            .subscribeOn(Schedulers.io())
            .observeOn(Schedulers.trampoline())
            .subscribeWith(object : Observer<CountriesAvailableResponseEnvelope> {
                override fun onComplete() {
                    println("onComplete")
                }

                override fun onNext(t: CountriesAvailableResponseEnvelope) {
                    println(t.countryCode)
                }

                override fun onError(e: Throwable) {
                    println(e.message)
                }
            })
    }

My retrofit setup looks like this:

  @Reusable
    @Provides
    fun provideRetrofit(context: Context, okHttpClient: OkHttpClient): Retrofit {
        return Retrofit.Builder()
            .baseUrl(http://www.holidaywebservice.com)
            .client(okHttpClient)
            .addConverterFactory(SimpleXmlConverterFactory.createNonStrict(Persister(AnnotationStrategy())))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build()
    }

Not sure if this is the reason why but I get this message in OnError:

I/System.out: org.simpleframework.xml.core.ConstructorException: Parameter 'soap12:Body' does not have a match in class nz.org.westforce.data.entities.holidaytest.CountriesAvailableRequestEnvelope

Many thanks for any suggestions

request

@Root(name = "soap:Envelope")
@NamespaceList(
    value = [
        Namespace(prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance"),
        Namespace(prefix = "xsd", reference = "http://www.w3.org/2001/XMLSchema"),
        Namespace(prefix = "soap", reference = "http://www.w3.org/2003/05/soap-envelope")
    ]
)
class CountriesAvailableRequestEnvelope(
    @field:Path("soap:Body")
    @field:Element(name ="GetCountriesAvailable")
    @param:Element(name ="GetCountriesAvailable")
    @field:Namespace(reference = "http://www.holidaywebservice.com/HolidayService_v2/")
    val getCountries: String = ""
)

use

val result = webServices.getAvailableCountries(CountriesAvailableRequestEnvelope())
...

response

@Root(name = "soap:Envelope")
@NamespaceList(
    value = [
        Namespace(prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance"),
        Namespace(prefix = "xsd", reference = " http://www.w3.org/2001/XMLSchema"),
        Namespace(prefix = "soap", reference = "http://www.w3.org/2003/05/soap-envelope")]
)
class CountriesAvailableResponseEnvelope {
    @field:Path("soap:Body")
    @field:Element(name = "GetCountriesAvailableResponse")
    @field:Namespace(reference = "http://www.holidaywebservice.com/HolidayService_v2/")
    var response: GetCountriesAvailableResponse? = null
}

@Element
class GetCountriesAvailableResponse {
    var GetCountriesAvailableResult: List<CountryCode>? = null
}

class CountryCode {
    @field:Element(name = "Description")
    var description: String? = null
    @field:Element(name = "Code")
    var code: String? = null
}

logcat

2019-04-08 12:00:23.989 22722-22748/nz.org.westforce.mobileui D/OkHttp: --> POST http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx
2019-04-08 12:00:23.989 22722-22748/nz.org.westforce.mobileui D/OkHttp: Content-Type: text/xml
2019-04-08 12:00:23.989 22722-22748/nz.org.westforce.mobileui D/OkHttp: Content-Length: 329
2019-04-08 12:00:23.989 22722-22748/nz.org.westforce.mobileui D/OkHttp: <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
2019-04-08 12:00:23.989 22722-22748/nz.org.westforce.mobileui D/OkHttp:    <soap:Body>
2019-04-08 12:00:23.989 22722-22748/nz.org.westforce.mobileui D/OkHttp:       <GetCountriesAvailable xmlns="http://www.holidaywebservice.com/HolidayService_v2/"></GetCountriesAvailable>
2019-04-08 12:00:23.989 22722-22748/nz.org.westforce.mobileui D/OkHttp:    </soap:Body>
2019-04-08 12:00:23.989 22722-22748/nz.org.westforce.mobileui D/OkHttp: </soap:Envelope>
2019-04-08 12:00:23.990 22722-22748/nz.org.westforce.mobileui D/OkHttp: --> END POST (329-byte body)
2019-04-08 12:00:24.363 22722-22748/nz.org.westforce.mobileui D/OkHttp: <-- 200 OK http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx (372ms)
2019-04-08 12:00:24.363 22722-22748/nz.org.westforce.mobileui D/OkHttp: Cache-Control: private, max-age=0
2019-04-08 12:00:24.363 22722-22748/nz.org.westforce.mobileui D/OkHttp: Content-Type: application/soap+xml; charset=utf-8
2019-04-08 12:00:24.363 22722-22748/nz.org.westforce.mobileui D/OkHttp: Server: Microsoft-IIS/8.5
2019-04-08 12:00:24.363 22722-22748/nz.org.westforce.mobileui D/OkHttp: X-AspNet-Version: 4.0.30319
2019-04-08 12:00:24.363 22722-22748/nz.org.westforce.mobileui D/OkHttp: X-Powered-By: ASP.NET
2019-04-08 12:00:24.363 22722-22748/nz.org.westforce.mobileui D/OkHttp: X-Powered-By-Plesk: PleskWin
2019-04-08 12:00:24.363 22722-22748/nz.org.westforce.mobileui D/OkHttp: Date: Mon, 08 Apr 2019 03:48:45 GMT
2019-04-08 12:00:24.363 22722-22748/nz.org.westforce.mobileui D/OkHttp: Content-Length: 983
2019-04-08 12:00:24.368 22722-22748/nz.org.westforce.mobileui D/OkHttp: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCountriesAvailableResponse xmlns="http://www.holidaywebservice.com/HolidayService_v2/"><GetCountriesAvailableResult><CountryCode><Code>Canada</Code><Description>Canada</Description></CountryCode><CountryCode><Code>GreatBritain</Code><Description>Great Britain and Wales</Description></CountryCode><CountryCode><Code>IrelandNorthern</Code><Description>Northern Ireland</Description></CountryCode><CountryCode><Code>IrelandRepublicOf</Code><Description>Republic of Ireland</Description></CountryCode><CountryCode><Code>Scotland</Code><Description>Scotland</Description></CountryCode><CountryCode><Code>UnitedStates</Code><Description>United States</Description></CountryCode></GetCountriesAvailableResult></GetCountriesAvailableResponse></soap:Body></soap:Envelope>
2019-04-08 12:00:24.369 22722-22748/nz.org.westforce.mobileui D/OkHttp: <-- END HTTP (983-byte body)

android, consuming xml webservice using retrofit Parameter `soap12:Body` does not have a match in class. 发表于 2019-03-31 15:16:34. 活跃于 2019-04-13 05:52:04. We listen too much about SAP PI as an integrator and every SAP connection is done thru it (that’s the best way to do it, I think) but it is not the only way. Since ERP 4.7 it is possible to consume/provide services directly from ABAP. When our scenario is SAP -> WebService the first thing we need is a working webservice. Test service:

You are missing one more class to to hold Body for request.

That is Envelope will contain Body object and Body will contain GetCountriesAvailable object.

Example:

@Root(name = "Envelope")
@NamespaceList(value = [
    Namespace(prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance"),
    Namespace(prefix = "xsd", reference = "http://www.w3.org/2001/XMLSchema"),
    Namespace(prefix = "soap12", reference = "http://www.w3.org/2003/05/soap-envelope")
])
data class CountriesAvailableRequestEnvelope(
    @Element(name = "Body", required = false)
    @Namespace(reference="http://www.w3.org/2003/05/soap-envelope", prefix:"soap12")
    val Body: Body)


@Root(name = "Body", strict = false)
@Namespace(reference="http://www.w3.org/2003/05/soap-envelope", prefix:"soap12")
data class Body(
    @Element(name = "GetCountriesAvailable", required = false)
    val countriesAvailableRequest: CountriesAvailableRequest)



@Root(name = "GetCountriesAvailable", strict = false)
@Namespace(reference = "http://www.holidaywebservice.com")
data class CountriesAvailableRequest(
    @Element(name = "GetCountriesAvailable", required = false) val code: String)

consuming xml webservice using retrofit Parameter `soap12:Body`, consuming xml webservice using retrofit Parameter `soap12:Body` does not have a match in class. Android Studio 3.4. I am testing the� Consume a RESTful Web Service. 05/28/2020; 8 minutes to read; In this article. Download the sample. Integrating a web service into an application is a common scenario. This article demonstrates how to consume a RESTful web service from a Xamarin.Forms application. Representational State Transfer (REST) is an architectural style for building web

Do not include prefix as part of element name.

Change

@Root(name = "soap12:Envelope")
@NamespaceList(value = [
    Namespace(prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance"),
    Namespace(prefix = "xsd", reference = "http://www.w3.org/2001/XMLSchema"),
    Namespace(prefix = "soap12", reference = "http://www.w3.org/2003/05/soap-envelope")
])

to

@Root(name = "Envelope")
@NamespaceList(value = [
    Namespace(prefix = "xsi", reference = "http://www.w3.org/2001/XMLSchema-instance"),
    Namespace(prefix = "xsd", reference = "http://www.w3.org/2001/XMLSchema"),
    Namespace(prefix = "soap12", reference = "http://www.w3.org/2003/05/soap-envelope")
])

And for Body element change as below.

@Root(name = "Body", strict = false)
 @Namespace(reference="http://www.w3.org/2003/05/soap-envelope")
data class CountryCode(
    @Element(name = "description", required = false) val description: String?,
    @Element(name = "code", required = false) val code: String?)

Bounty wrongly assigned to my answer, consuming xml webservice using retrofit Parameter `soap12:Body` does not The provision that half the bounty is awarded to a top-voted answer mostly owner intentionally decides not to give the full amount to an existing answer; they can try and get a moderator to clear away their previous bounty,� Like most open-source software, Retrofit was built on top of some other powerful libraries and tools. Behind the scenes, Retrofit makes use of OkHttp (from the same developer) to handle network requests. Also, Retrofit does not have a built-in JSON converter to parse from JSON to Java objects.

Retrofit Soap Service Parsing "Body" mismatched with model � Issue , ElementException:Element 'Body' does not have a match in class GitHub is home to over 50 million developers working together to host and Even I have matched correct parameters with model it keep showing This is a usage question about Simple XML and not a bug or feature request for Retrofit. Java restful webservices with HTTP basic authentication. In the context of a HTTP transaction, basic access authentication is a method for an HTTP user agent to provide a user name and password when making a request.

レトロフィットパラメータ 'soap12:body'を使用してXML Web , を消費するクラスで一致しません � consuming xml webservice using retrofit Parameter `soap12:Body` does not have a match in class. By using retrofit annotation its encode the ASP.Net Web API EndPoint into the interface in simplify way for us to call the methods and passing the parameters, so go to WebAPIClient > app > src > main > java > instinctcoder.webapiclient add an Interface with this name, InstituteService. and the code in this file will look like this

How to disable a body data getting encoded in soap, retrofit request , I have a request data where one of the element takes xml as value. While sending the data to the server using #Body my inner xml is getting encoded(html encoded). How to disable the inner xml getting encoded. sample: <soap12: Envelope I would suggest that you check if the values are matching the parameters, and� SOAP is a protocol specification for exchanging structured information in the implementation of Web Services in computer networks. It relies on Extensible Markup Language (XML) for its message format and usually relies on other Application Layer protocols, most notably Hypertext Transfer Protocol (HTTP) and Simple Mail Transfer Protocol (SMTP), for message negotiation and transmission.

Comments
  • Hi, thanks for your response. However, I am still getting the following in onError this is the error message org.simpleframework.xml.core.ConstructorException: Parameter 'Body' does not have a match in class nz.org.westforce.data.entities.holidaytest.CountriesAvailableResponseEnvelope
  • However, I do get the same output as your OKHttp, But the onError is thrown rather than the onNext so cannot get my data back from the response.
  • @ant2009 has add response bean
  • Thanks, its working. Can you just explain the annotation for field:element, field:path, and field:namespace. I had this missing my code.
  • @ant2009 check this stackoverflow.com/questions/45741617/…
  • Thanks for the update. However, I am still getting an error in the onError message.org.simpleframework.xml.core.ConstructorException: Parameter 'Body' does not have a match in class nz.org.westforce.data.entities.holidaytest.CountriesAvailableRequestEnvelope I have pushed my changes to this github repo if you want to check the code: https://github.com/steve1rm/WestcreditUnion
  • Because the project is using build.gradle.kts. You will need to remove the .idea directory before importing. And create a local.properties with the path to your sdk
  • Hi, Thanks for the answer. However, after making those changes I am not getting the following: ConstructorException: Parameter 'Body' does not have a match in class nz.org.westforce.data.entities.holidaytest.CountriesAvailableRequestEnvelope
  • I have just updated my question to reflect the changes you request. The error is in the OnError of the RxJava.
  • This is the onError message RuntimeException: org.simpleframework.xml.core.ConstructorException: Parameter 'Body' does not have a match in class nz.org.westforce.data.entities.holidaytest.CountriesAvailableRequestEnvelope
  • I see you are missing @Namespace(reference="http://www.w3.org/2003/05/soap-envelope") line for your Body class for response.
  • Still getting the same error. I have updated my question with your last answer