简体   繁体   中英

send the unicode value from Android to C# Webservice

I'm trying to send the Unicode value to WCF web service from Android app but I keep getting the string value as ????? in WCF web service. Below are the android code and C# code for web service.

                GTPostData gtPostData = new GTPostData(); //DTO Object
                Gson gson = new Gson();

                String post = "イメージお願いし";

                gtPostData.setPortalId(portalId);
                gtPostData.setPost(post);
                gtPostData.setProjectId(data.getProjectId());
                gtPostData.setQuestionId(data.getQuestionId());
                gtPostData.setUserId(panelistId);

                GTPostDataRequest request = new GTPostDataRequest();
                request.setGtPostData(gtPostData);//creating the request object

                JSONObject jsonObject = new JSONObject(gson.toJson(request)); 

                String webServiceUrl= ResourcePicker.getServiceURL(session.getPortal(),session.getPortalId(),true);
                String addGtPostMethod = ResourcePicker.getString(portal, "add_gt_post");

                AsyncPostRequest asyncRequest = new AsyncPostRequest();
                asyncRequest.setServiceMethod(addGtPostMethod);
                asyncRequest.setServiceUrl(webServiceUrl);
                asyncRequest.setPostObject(jsonObject);//set object for post call
                SendGtPostAsyncService asyncService = new SendGtPostAsyncService(asyncRequest, context, session, db, data.getPostId());
                asyncService.execute();//call the async task

WCF web service call (C#)

public bool AddGTPost(GTPostData GtPostData)
        {
            bool isAdded = false;
            try
            {
                sci.Debug(frendlyName, screenName, "", "Enter AddGTPost ->> " + GtPostData);//These are trace methods which will print the results in txt file.


                sci.Debug(frendlyName, screenName, "", "Enter AddGTPost - Unicode Post ->> " + GtPostData.post);//These are trace methods which will print the results in txt file. Here I'm getting results as "??????"

So please some one help me what is my mistake here?

For your webservice I hope you are not missing UTF-16 format also in the configuration you are using :

    Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);
    GlobalizationSection configSection = (GlobalizationSection)config.GetSection("system.web/globalization");            
    configSection.RequestEncoding = Encoding.Unicode;
    configSection.ResponseEncoding = Encoding.Unicode;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM