开发者

Regarding Stringbuilder in c#

is stringbuilder is same in android java and c# ??

im using stringbuilder in c#(REST Webservice).. how can i use with the same functionality in Java?

or im using stringentity in java.wat is the equivalent in c#(RES开发者_C百科T Webservice)?

HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit

HttpResponse response;
JSONObject json = new JSONObject();
String URL ="url";
try{

     HttpPost post = new HttpPost(URL);
     json.put("CNo",112);
     json.put("CName",name);

     StringEntity se = new StringEntity(json.toString());
     se.setContentType("application/json; charset=utf-8");
     se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json; charset=utf-8"));

     post.setHeader("Accept","application/json");
     post.setHeader("Content-type","application/json; charset=utf-8");
     String ss= post.toString();
     response = client.execute(post);

this is for post()

and in webservice im implementing by

public bool CreateCustomer(StringBuilder strObj)
{
    // JavaScriptSerializer js = new JavaScriptSerializer();
    //  Customer custObj = js.Deserialize<Customer>(strObj.ToString());
    //  strObj.ToString();
    bool Inserted = false;
    String connString = ConfigurationManager.ConnectionStrings["connWebOrdering"].ConnectionString;
    SqlConnection Conn = new SqlConnection(connString);
    try
    {
        SqlCommand cmd = new SqlCommand("insert into cust(obj) values('" + strObj + "')", Conn);
        Conn.Open();
        int rowsaffected = cmd.ExecuteNonQuery();
        if (rowsaffected == 1)
        {
            Inserted = true;
        }
    }
    catch (Exception)
    { }
    finally
    {
        Conn.Close();
    }

here the inserted data in database is "blank"... the response comes to as "OK..Status 200"


Why are you trying to pass the entire object?

You can't pass a stringbuilder object from one programming paradigm to another - i.e., even if you serialise the StringBuilder object in Java, I'm suspecting you won't be able to suck it into a C# StringBuilder (unless a serialised StringBuilder in java is simply a string).

You'll have to pass the string contained within the stringbuilder object as a string. The C# stringbuilder can then construct itself using the provided string as it's initial state.

This goes for any object -- it will be easier and simpler to pass through the simple item rather than an entire object, so cast everything down to it's most basic (primitive) type (string, int, if it's XML, serialise it to a string: the remote end can deserialise), etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜