1

有用 C# 编写的 WEB 服务,使用下一个方法:

[WebMethod]
public string ByteArrTest(byte[] Buffer)
{
if (Buffer == null) return "buffer is null";
else return Buffer.Length.ToString() + " is buffer length";
}

我喜欢使用 Ksoap2 库从 android 设备调用此方法,类似于 belove(简化):

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;

new MarshalBase64().register(envelope);
        envelope.encodingStyle = SoapEnvelope.ENC;

SoapObject request = new SoapObject(this.getNameSpace(), this.getMethodName());

PropertyInfo pi4 = new PropertyInfo();
        pi4.setName("Buffer");
        byte [] b="this text".getBytes();
        pi4.setValue(b);
    pi4.setType(byte[].class);
// request.addProperty("buffer", "bytes".getBytes);
request.addProperty(pi4);
 envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = 
new    HttpTransportSE(this.getURL());//

androidHttpTransport.call(this.getSoapAction(), envelope);
Object response = envelope.getResponse();
//next implementation 

响应总是“缓冲区为空”什么是不正确或错误的?感谢您的关注

4

1 回答 1

0

在调用 Web 服务的 Android 中发布整个方法会更有帮助。

我在我目前正在处理的 Android 项目中使用 KSoap,我正在检索字符串。这是我修改的方法之一以匹配您的需要:

    private static String NAMESPACE = "http://tempuri.org/";
private static String SOAP_ACTION = "http://tempuri.org/";
private static final String URL = "Your url link to your web services asmx file";

        public static String ByteArrTestCall(byte[] t) {

    String resTxt = null;
    SoapObject request = new SoapObject(NAMESPACE, "ByteArrTest");
    // Add the property to request object
    request.addProperty("Buffer", t);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;
    try
    {
    androidHttpTransport.call(SOAP_ACTION+"ByteArrTest", envelope);
    SoapPrimitive receivedString = (SoapPrimitive) envelope.getResponse();
    resTxt = receivedString.toString();
    }
    catch(Exception e)
    {
        resTxt = androidHttpTransport.requestDump;
        return e.toString() + resTxt;
    }

    return resTxt;
}
于 2014-04-02T14:16:35.133 回答