为什么没有web服务工作手动? [英] Why doesn't webservice work manually?

查看:91
本文介绍了为什么没有web服务工作手动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有多个方法Web服务。我使用Firefox的插件soaclient测试它们。所有方法都正常工作。这些都是正常的,直到如今。我写的库在Android呼叫这些.NET Web服务。我有方法,第一个prepares包围,另外一个调用方法。除了这些方法之一工作的所有方法。我得到prepared从我的lib中的方法不起作用,并使用Firefox SOAP客户端在这个信封包裹,它返回我正确的方法应对。我调用Web服务不起作用错自己的方法,只是返回空的结果。可能是什么错误?

 私人无效createEnvelope(){
    //她井parametreninkalıbı
    字符串PARAMS =<%S>%S< /%S>中;
    //她parametrekalıbınadeğeratandığındageçiciolarak tutulan串
    串paramsTemp =;
    //HazırlananTUM parametrelerintutulduğudeğişken
    串paramsAll =;    // Parametreler ekleniyor
    的for(int i = 0; I< parameterKeys.size();我++){
        paramsTemp =的String.format(参数,可以parameterKeys.get(ⅰ),
                parameterValues​​.get(i)中,parameterKeys.get(ⅰ));
        paramsAll + = paramsTemp;
    }    //肥皂mesajınıhazılıyoruz
    字符串soapTemplate =< XML版本= \\%s \\的编码= \\%s \\的>?
            +<肥皂:信封的xmlns:XSI = \\HTTP://www.w3.org/2001/XMLSchema-instance \\的xmlns:XSD = \\HTTP://www.w3.org/2001/XMLSchema \\ 的xmlns:SOAP = \\HTTP://schemas.xmlsoap.org/soap/envelope/ \\>中
            +<肥皂:身体与GT; +<%S的xmlns = \\%s \\的>中+%S+< /%S>中
            +< / SOAP:身体与GT; +< / SOAP:信封>中;
    信封=的String.format(soapTemplate,版本,charEncoding,
            方法名,命名空间,paramsAll,方法名);
    Logger.log(要求:+包);
}
公共字符串callWebService(){    createEnvelope();
    //请求参数
    的HttpParams PARAMS = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(参数,可以connectionTimeOut);
    HttpConnectionParams.setSoTimeout(参数,可以soTimeOut);    //设置参数
    HttpProtocolParams.setUseExpectContinue(httpClient.getParams(),TRUE);    // POST信封
    HttpPost httppost =新HttpPost(URL);    //添加页眉
    httppost.setHeader(SOAPAction报的soapAction);
    httppost.setHeader(内容类型的contentType);    尝试{        //实体持有请求
        HttpEntity实体=新StringEntity(信封);
        httppost.setEntity(实体);        //响应处理器
        ResponseHandler所<串GT; RH =新ResponseHandler所<串GT;(){
            //当客户端接收响应调用
            公共字符串用handleResponse(HTT presponse responseTemp)
                    抛出ClientProtocolException,IOException异常{                //得到响应实体
                HttpEntity实体= responseTemp.getEntity();
                状态行状态行= responseTemp.getStatusLine();                //读取响应的字节数组
                StringBuffer的出=新的StringBuffer();
                字节[] B = EntityUtils.toByteArray(实体);                //写响应字节数组字符串缓冲区
                out.append(新的String(B,0,b.length个));
                返回out.toString();
            }
        };        响应= httpClient.execute(httppost,RH);    }赶上(例外五){
        Log.v(SOAP服务异常,e.toString());
    }    //关闭连接
    。httpClient.getConnectionManager()关机();
    返回响应;
}

修改

在logcat的请求模板:

 <?XML版本=1.0编码=UTF-8&GT?;
<肥皂:信封的xmlns:SOAP =htt​​p://schemas.xmlsoap.org/soap/envelope/的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:XSD = http://www.w3.org/2001/XMLSchema\">
   <肥皂:身体与GT;
      < METHOD_NAME的xmlns =URL>
         <&参数1 GT; 12345< /参数1>
         <参数2>ügıtç< /参数2>
         <参数3>&QWERT LT; /参数3>
      < / METHOD_NAME>
   < / SOAP:身体与GT;
< / SOAP:信封>

在logcat的响应模板

 <?XML版本=1.0编码=UTF-8&GT?;
<肥皂:信封的xmlns:SOAP =htt​​p://schemas.xmlsoap.org/soap/envelope/的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:XSD = http://www.w3.org/2001/XMLSchema\">
   <肥皂:身体与GT;
      < Method_Name_Response的xmlns =URL>
         < Method_Name_Result>
            < XS:架构的xmlns:XS =htt​​p://www.w3.org/2001/XMLSchema中的xmlns =的xmlns:MSDATA =瓮:架构 - 微软COM:XML-MSDATAID =NewDataSet >
               < XS:元素的名称=NewDataSetMSDATA:IsDataSet =真MSDATA:UseCurrentLocale =真正的>
                  < XS:复杂类型>
                     < XS:选择的minOccurs =0的maxOccurs =无界>
                        < XS:元素的名称=温度>
                           < XS:复杂类型>
                              < XS:序列>
                                 < XS:元素的名称=response1类型=XS:长的minOccurs =0/>
                                 < XS:元素的名称=响应2类型=XS:字符串的minOccurs =0/>
                              < / XS:序列>
                           < / XS:复杂类型>
                        < / XS:组件>
                     < / XS:选择>
                  < / XS:复杂类型>
               < / XS:组件>
            < / XS:架构>
            < diffgr:的DiffGram的xmlns:diffgr =瓮:架构 - 微软COM:XML-的DiffGram-V1的xmlns:MSDATA =瓮:架构 - 微软COM:XML-MSDATA/>
         < / Method_Name_Result>
      < / Method_Name_Response>
   < / SOAP:身体与GT;
< / SOAP:信封>

在Firefox插件具有相同的信封响应模板

 <?XML版本=1.0编码=UTF-8&GT?;
<肥皂:信封的xmlns:SOAP =htt​​p://schemas.xmlsoap.org/soap/envelope/的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:XSD = http://www.w3.org/2001/XMLSchema\">
   <肥皂:身体与GT;
      < Method_Name_Response的xmlns =URL>
         < Method_Name_Result>
            < XS:架构的xmlns:XS =htt​​p://www.w3.org/2001/XMLSchema中的xmlns =的xmlns:MSDATA =瓮:架构 - 微软COM:XML-MSDATAID =NewDataSet >
               < XS:元素的名称=NewDataSetMSDATA:IsDataSet =真MSDATA:UseCurrentLocale =真正的>
                  < XS:复杂类型>
                     < XS:选择的minOccurs =0的maxOccurs =无界>
                        < XS:元素的名称=温度>
                           < XS:复杂类型>
                              < XS:序列>
                                 < XS:元素的名称=response1类型=XS:长的minOccurs =0/>
                                 < XS:元素的名称=响应2类型=XS:字符串的minOccurs =0/>
                              < / XS:序列>
                           < / XS:复杂类型>
                        < / XS:组件>
                     < / XS:选择>
                  < / XS:复杂类型>
               < / XS:组件>
            < / XS:架构>
            < diffgr:的DiffGram的xmlns:diffgr =瓮:架构 - 微软COM:XML-的DiffGram-V1的xmlns:MSDATA =瓮:架构 - 微软COM:XML-MSDATA>
               < NewDataSet的xmlns =>
                  &下;温度diffgr:ID =TEMP1MSDATA:rowOrder =0>
                     < response1> 123456789< / response1>
                     <&响应2 GT; Android和LT; /响应2​​>
                  < /温度>
               < / NewDataSet>
            < / diffgr:&的DiffGram GT;
          < / Method_Name_Result>
      < / Method_Name_Response>
   < / SOAP:身体与GT;
< / SOAP:信封>


解决方案

我发现我的问题,土耳其的字符会导致错误。当我使用ü它会导致错误,当我不使用它,它可以完美运行。

I have webservice that has more than one method. I use firefox soaclient plugin for test them. All methods work properly. These are normal until now. I wrote library on android for call these .net webservice. I have methods, first one prepares envelop, the other one calls method. All methods except one work with these way. I get prepared envelop from my lib for method that doesn't work and use this envelope on firefox soap client, it returns me response in correct way. My own method that calls web service doesn't work wrong, just return empty result. What could be the error?

private void createEnvelope() {
    // Her bir parametrenin kalıbı
    String params = "<%s>%s</%s>";
    // Her parametre kalıbına değer atandığında geçici olarak tutulan string
    String paramsTemp = "";
    // Hazırlanan tüm parametrelerin tutulduğu değişken
    String paramsAll = "";

    // Parametreler ekleniyor
    for (int i = 0; i < parameterKeys.size(); i++) {
        paramsTemp = String.format(params, parameterKeys.get(i),
                parameterValues.get(i), parameterKeys.get(i));
        paramsAll += paramsTemp;
    }

    // soap mesajını hazılıyoruz
    String soapTemplate = "<?xml version=\"%s\" encoding=\"%s\"?>"
            + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
            + "<soap:Body>" + "<%s xmlns=\"%s\">" + "%s" + "</%s>"
            + "</soap:Body>" + "</soap:Envelope>";
    envelope = String.format(soapTemplate, version, charEncoding,
            methodName, namespace, paramsAll, methodName);
    Logger.log("request:" + envelope);
}


public String callWebService() {

    createEnvelope();
    // request parameters
    HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, connectionTimeOut);
    HttpConnectionParams.setSoTimeout(params, soTimeOut);

    // set parameter
    HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), true);

    // POST the envelope
    HttpPost httppost = new HttpPost(url);

    // add headers
    httppost.setHeader("SOAPAction", soapAction);
    httppost.setHeader("Content-Type", contentType);

    try {

        // the entity holds the request
        HttpEntity entity = new StringEntity(envelope);
        httppost.setEntity(entity);

        // Response handler
        ResponseHandler<String> rh = new ResponseHandler<String>() {
            // invoked when client receives response
            public String handleResponse(HttpResponse responseTemp)
                    throws ClientProtocolException, IOException {

                // get response entity
                HttpEntity entity = responseTemp.getEntity();
                StatusLine statusLine = responseTemp.getStatusLine();

                // read the response as byte array
                StringBuffer out = new StringBuffer();
                byte[] b = EntityUtils.toByteArray(entity);

                // write the response byte array to a string buffer
                out.append(new String(b, 0, b.length));
                return out.toString();
            }
        };

        response = httpClient.execute(httppost, rh);

    } catch (Exception e) {
        Log.v("Soap Service Exception:", e.toString());
    }

    // close the connection
    httpClient.getConnectionManager().shutdown();
    return response;
}

EDIT

Request template on logcat:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <Method_Name xmlns="url">
         <param1>12345</param1>
         <param2>ügıtç</param2>
         <param3>qwert</param3>
      </Method_Name>
   </soap:Body>
</soap:Envelope>

response template on logcat

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <Method_Name_Response xmlns="url">
         <Method_Name_Result>
            <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
               <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
                  <xs:complexType>
                     <xs:choice minOccurs="0" maxOccurs="unbounded">
                        <xs:element name="Temp">
                           <xs:complexType>
                              <xs:sequence>
                                 <xs:element name="response1" type="xs:long" minOccurs="0" />
                                 <xs:element name="response2" type="xs:string" minOccurs="0" />
                              </xs:sequence>
                           </xs:complexType>
                        </xs:element>
                     </xs:choice>
                  </xs:complexType>
               </xs:element>
            </xs:schema>
            <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" />
         </Method_Name_Result>
      </Method_Name_Response>
   </soap:Body>
</soap:Envelope>

response template on firefox plugin with same envelope

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <Method_Name_Response xmlns="url">
         <Method_Name_Result>
            <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
               <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
                  <xs:complexType>
                     <xs:choice minOccurs="0" maxOccurs="unbounded">
                        <xs:element name="Temp">
                           <xs:complexType>
                              <xs:sequence>
                                 <xs:element name="response1" type="xs:long" minOccurs="0" />
                                 <xs:element name="response2" type="xs:string" minOccurs="0" />
                              </xs:sequence>
                           </xs:complexType>
                        </xs:element>
                     </xs:choice>
                  </xs:complexType>
               </xs:element>
            </xs:schema>
            <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
               <NewDataSet xmlns="">
                  <Temp diffgr:id="Temp1" msdata:rowOrder="0">
                     <response1>123456789</response1>
                     <response2>Android</response2>
                  </Temp>
               </NewDataSet>
            </diffgr:diffgram>
          </Method_Name_Result>
      </Method_Name_Response>
   </soap:Body>
</soap:Envelope>

解决方案

I found my problem, Turkish characters causes the error. When I use "ü" it causes error, when I don't use it, it works perfect.

这篇关于为什么没有web服务工作手动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆