现有C#开发的WebService下的一个方法:
 [WebMethod]
 public int TestByteArray(string strIn, byte[] strRequest)
{
   // 相关实现
   return 0;
}目前准备使用HTTP POST方式调用该方法,请问该如何写代码?
用HttpPost类操作的话,这个byte[]不知道该如何传递。
还请大虾支招。PS: 回复使用SOAP方式调用的就别浪费时间回复了,用KSOAP2我也知道调用。下面提供一个网上找到的单个参数传递byte[]的方式, 多个参数中,带有byte[]的就搞不定了:public boolean post(byte[] paramArrayOfByte,String http)  {  ByteArrayEntity arrayEntity=new ByteArrayEntity(paramArrayOfByte);  arrayEntity.setContentType("application/octet-stream");  HttpPost httpPost=new HttpPost(http);  httpPost.setEntity(arrayEntity);  DefaultHttpClient client=new DefaultHttpClient();  try {  int result=client.execute(httpPost).getStatusLine().getStatusCode();  Log.i("XXXXXXXXXXXXXXX", result);  } catch (Exception e) {  throw new RuntimeException(e);  }  return false;  }

解决方案 »

  1.   

    Webservice 其实就是HTTP上的一种XML协议,二进制的要专成base64编码,放到xml里,首先你要明白XML.建议你用SoapUI工具.
      

  2.   

    一定要用HTTP协议?我现在用Soap调用,方法很简单
     [WebMethod]
            public string GetMsecondNameByMsecondId(string MsecondId)
            {            return msm.GetMsecondNameByMsecondId(MsecondId);
            }
    public String GetMsecondNameByMsecondId(String MsecondId){
    String name=null;
         SoapObject request = new SoapObject("http://tempuri.org/", "GetMsecondNameByMsecondId");  
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);   
            request.addProperty("MsecondId",MsecondId);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            AndroidHttpTransport  ht = new AndroidHttpTransport("http://192.168.1.70/AndroidService/AndroidService.asmx");
            (new MarshalBase64()).register(envelope);//放着没错
             try {
     ht.call("http://tempuri.org/GetMsecondNameByMsecondId",envelope);
     
     SoapPrimitive soap = (SoapPrimitive) envelope.getResponse(); 
     name=soap.toString();
             }catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
             }
             return name;
    }
      

  3.   

    我也是最近才搞明白
    其实,整个WEBSERVIC就是提交一个XML,返回一个XML
    那你提交的XML的格式怎样呢?
    只要你的浏览器中访问这个方法就可以看到了,我用的是SOAP 1.2中的.
    看下这里,看能不能帮到你。
    http://topic.csdn.net/u/20110308/14/119a4aa2-9c7b-4abb-9a5c-6774aa047b4b.html