gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:16:52 27 4
gpt4 key购买 nike

我有以下调用 .net 网络服务的代码。代码可以很好地连接到服务,但参数(deviceid)似乎没有通过。该方法仅返回传递的 deviceid,它始终为 null。

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

Activity 代码

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

}

网络服务代码

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

谢谢

帕特里克

最佳答案

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

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

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

就数据包嗅探器而言,查看 wire shark .

关于.net - 将简单字符串参数传递给 .net webservice 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3085227/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com