Android Question Failing to pass parameter to ASP.Net Webservice

Makumbi

Well-Known Member
Licensed User
when i browse my webservice manually this is what i see in my browser
http://192.168.1.239/WebServicesula/Service.asmx?op=Delete

B4X:
Test
To test the operation using the HTTP POST protocol, click the 'Invoke' button.
Parameter    Value
customerId:   
SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

POST /Service.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Delete"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Delete xmlns="http://tempuri.org/">
      <customerId>int</customerId>
    </Delete>
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <DeleteResponse xmlns="http://tempuri.org/" />
  </soap:Body>
</soap:Envelope>
SOAP 1.2
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.

POST /Service.asmx HTTP/1.1
Host: localhost
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>
    <Delete xmlns="http://tempuri.org/">
      <customerId>int</customerId>
    </Delete>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
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>
    <DeleteResponse xmlns="http://tempuri.org/" />
  </soap12:Body>
</soap12:Envelope>
HTTP POST
The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.

POST /Service.asmx/Delete HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length

customerId=string
HTTP/1.1 200 OK


on running app
B4X:
Dim Job As HttpJob
    Dim Job2 As HttpJob

    Job.Username="..."
    Job.Password="..."
    Job2.Username="..."
    Job2.Password="..."
Job2.Initialize("Job2", Me)
    Job2.PostString("http://192.168.1.239/WebServicesula/Service.asmx?op=Delete", "1003")


i now gett this message
 

OliverA

Expert
Licensed User
Longtime User
POST /Service.asmx/Delete HTTP/1.1
Host: localhost
Content-
Type: application/x-www-form-urlencoded
Content-Length: length

customerId=
string
HTTP/1.1 200 OK
1) According to this, your URL should be
B4X:
http://192.168.1.239/Service.asmx/Delete
not
B4X:
http://192.168.1.239/WebServicesula/Service.asmx?op=Delete
2)
Your posted string should be in the format
B4X:
customerId=string
which in your example than should be
B4X:
"customerId=1003"
instead of just
B4X:
"1003"
3) Finally, you need
Content-Type: application/x-www-form-urlencode
which you can do by placing this code
B4X:
Job2.GetRequest.SetContentType("application/x-www-form-urlencoded")
after your
B4X:
Job2.PostString(...)
line.
Note, you need to include the OkHttp library to access the SetContentType method of the GetRequest object.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…