将简单字符串参数传递给 .net webservice 时出现问题

发布于 2024-09-06 10:22:26 字数 2922 浏览 6 评论 0原文

我有以下调用 .net Web 服务的代码。代码可以正常连接到服务,但参数(deviceid)似乎没有通过。该方法只是返回传递的 deviceid,该 ID 始终为 null。

这告诉我 deviceid 参数没有被传递。我想我看到有人推荐一个数据包嗅探器来查看传出的 xml,但似乎不记得它是什么。有人可以推荐一个我可以与 eclipse 和 windows 结合使用的吗?

活动代码

    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();

    }

web 服务代码

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

        Return deviceid
    End Function

我已经尝试了所有方法,但无法弄清楚如何解决此问题。还有其他人有什么建议可以尝试吗?

从wire shark作为间谍发送的xml:

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/soap/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>

谢谢

帕特里克

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/soap/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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

过潦 2024-09-13 10:22:26

如果我没记错的话,ht.call(...) 返回一个 SoapSerializationEnvelope。我相信您需要从信封中取出您的回复,而不是从您传递的信封中取出您的回复

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

如果这不起作用:
您是否使用 ksoap2 for android(有 Java 版本和 Android 版本)?您的网络服务需要您登录吗?在尝试执行类似的任务时,我发现 ksoap 没有存储会话 cookie,特别是会话 id。我们必须扩展 ServiceConnection 和 HttpTransportSE 将 cookie 保存为字符串,以便维护登录。

就数据包嗅探器而言,请查看 钢丝鲨.

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.

对你的占有欲 2024-09-13 10:22:26

尝试设置 PropertyInfo 对象的命名空间。

    pi.setNamespace(NAMESPACE);

Try setting the namespace of the PropertyInfo object.

    pi.setNamespace(NAMESPACE);
如日中天 2024-09-13 10:22:26

尝试从 Web 服务中的命名空间中删除冒号 (:)...即只需将其设为 ikonicsoft.com 而不是 http://ikonicsoft.com - 并更新您的Soap 引用也调用以使用新的命名空间。这很疯狂,但这解决了我的问题(在黑莓上,但我认为同样的原则适用)。

编辑 - 如果您尝试使用不属于您的 Web 服务,这并不理想,但它至少是使用您自己的 Web 服务的解决方案。我非常困惑为什么其中的冒号会把事情搞砸,但我注意到直接向 Web 服务器发送 HTML 帖子(通过远程登录到 Web 服务器上的端口 80),我得到了同样的错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文