将unicode值从Android发送到C#Webservice

时间:2017-04-27 12:36:55

标签: c# android asp.net web-services wcf

我试图从Android应用程序将Unicode值发送到WCF Web服务,但我一直得到字符串值为?????在WCF Web服务中。下面是用于Web服务的android代码和C#代码。

                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服务调用(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 "??????"

所以请有人帮助我,这是我的错误吗?

1 个答案:

答案 0 :(得分:0)

对于您的网络服务,我希望您不会错过UTF-16格式 也在你正在使用的配置中:

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