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
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
<?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><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt; System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent()
at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)
--- End of inner exception stack trace ---</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>
 

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
Top