开发者

Problem passing simple string parameter to .net webservice

I have the following code which invokes a .net webservice. The code connects to the service fine, but the paramter(deviceid) does not appear to get passed. The method simply returns the passed deviceid which is always null.

This is telling me the deviceid parameter is not being passed. I thought I saw someone recommend a packet sniffer to view the outgoing xml, but can't seem to remember what it was. Can someone suggest one that i can use in conjunction with eclipse and windows.

activity code

    String deviceid = tManager.getDeviceId();

    SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

    PropertyInfo pi = new PropertyInfo();

    pi.setName("deviceid");
    pi.type = PropertyInfo.STRING_CLASS;
    pi.setValue(deviceid.toString());
    request.addProperty(pi);

    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.dotNet = true;
    soapEnvelope.setOutputSoapObject(request);

    HttpTransportSE ht = new HttpTransportSE(URL);


    try{
        ht.call(SOAP_ACTION, soapEnvelope);
        SoapPrimitive result = (SoapPrimitive ) soapEnvelope.getResponse(); 


        Toast.makeText(ctx, "result = " + result.toString(), Toast.LENGTH_SHORT).show();

    }catch(Exception e){
        e.printStackTrace();
        Toast.makeText(ctx, "error: " + e.getMessage(), Toast.LENGTH_SHORT).show();

    }

webservice code

        <WebMethod()> _
    Public Function CheckTrial(ByVal deviceid As String) As String

        Return deviceid
    End Function

I,ve tried everything and cannot figure out how to resolve this. Does anyone else have any suggestions to try?

xml sent as spy'ed from wire shark:

POST /android_service_test.asmx HTTP/1.1 
Host: ikonicsoft.com 
user-agent: kSOAP/2.0 
soapaction: http://ikonicsoft.com/CheckTrial 
content-type: text/xml 
connection: close 
content-length: 421  
<?xml version="1.0" encoding="UTF-8"?>
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:d="http://www.w3.org/2001/XMLSchema" 
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:v="http://schemas.xmlsoap.org/s开发者_C百科oap/envelope/">
<v:Header />
<v:Body>
    <CheckTrial xmlns="http://ikonicsoft.com" id="o0" c:root="1">
        <deviceid i:type="d:string">000000000000000</deviceid>
    </CheckTrial>
</v:Body>
</v:Envelope>

HTTP/1.1 200 OK 
Connection: close 
Date: Mon, 21 Jun 2010 16:35:10 GMT 
Server: Microsoft-IIS/6.0 
X-Powered-By: PleskWin 
X-Powered-By: ASP.NET 
X-AspNet-Version: 2.0.50727 
Set-Cookie: .ASPXANONYMOUS=fnyqjfFHywEkAAAAZGVjYjZmNTEtNWNiYi00YTIwLWEzYzktNzUxZDNjMDA0OGY00; 
expires=Mon, 30-Aug-2010 03:15:09 GMT; path=/; HttpOnly 
Cache-Control: private, max-age=0 
Content-Type: text/xml; charset=utf-8 
Content-Length: 299  

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
    <CheckTrialResponse xmlns="http://ikonicsoft.com/" />
</soap:Body>
</soap:Envelope>

Thanks

Patrick


If I'm not mistaken, ht.call(...) returns a SoapSerializationEnvelope. I believe you need to pull your response out of that envelope and not out of the one you passed in

SoapSerializationEnvelope responseEnvelope = ht.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive result = (SoapPrimitive ) responseEnvelope.getResponse(); 

If that doesnt work: Are you using ksoap2 for android (there is a Java version and an Android version)? does your webservice require you to log in? while trying to perform a similar task i found that ksoap was not storing session cookies, particularly the session id. we had to extend ServiceConnection and HttpTransportSE to save the cookie as a String in order to maintain a login

As far as packet sniffers go, check out wire shark.


Try setting the namespace of the PropertyInfo object.

    pi.setNamespace(NAMESPACE);


Try removing the colon (:) from your namespace in the webservice... ie just make it ikonicsoft.com instead of http://ikonicsoft.com - and update your soap reference calls as well to use the new namespace. It's crazy, but this solved my problem (on Blackberry, but the same principles apply I think).

Edit - this isn't ideal if you are trying to consume a webservice that you don't own, but it's at least a solution for consuming your own webservices. I am absolutely baffled as to why the colon in there is messing things up, but I noticed that doing an HTML post directly to the web server (by telnetting in to port 80 on the webserver), I get the same error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜