質問

Microsoft AzureにASMX Webサービスのセットアップがあり、Webサービスにデータを送信し、Androidアプリケーションを使用して出力を受信しようとしています。この目的のために、私はKSOAPライブラリを使用しています。

ウェブサービスでは、文字列がnullかどうかを確認しています。もしそうなら、エラーコード「2405」を返します

[WebMethod]
        public string LoginUser(string auth_token, string username)
        {
            // All these tests performed, so someone from outside of out application
            // scope does not attempt to abuse our webservice.
            #region Check for nulls
            if (string.IsNullOrEmpty(auth_token))
                return "2405";
            if (string.IsNullOrEmpty(username))
                return "2405";
            #endregion
        }

Androidアプリケーションでは、データを送信していますが、Webサービスは2405エラーコードを引き続き返します。つまり、データは送信されません。

以下は私のAndroidコードです:

        SoapObject request = new SoapObject(NAMESPACE, method_name);

        PropertyInfo pi = new PropertyInfo();
        pi.setName("auth_token");
        pi.setValue("TestAuth");
        request.addProperty(pi);

        PropertyInfo pe = new PropertyInfo();
        pe.setName("username");
        pe.setValue("TestUser");
        request.addProperty(pe);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);

申し訳ありませんが、名前空間、MethodName、URLなどを提供できます。それは会社のポリシーに反しているので、理解していただければ幸いです。 :)

それにもかかわらず、もう一度エラーを確認します。上記のAndroidコードを呼び出した後、WebServiceは2405を返します。これは、ASMXコードによると、Twos値のいずれかがNULLの場合です。

アップデート: SOAPリクエスト(androidhttptransport.debug = true)をデバッグし、requestDumpとrespondedumpで次の結果を得ました。

ダンプをリクエストします

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:d="http://www.w3.org/2001/XMLSchema" 
            xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
            xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
  <v:Header />
  <v:Body>
    <LoginUser xmlns="http://tempuri.org" id="o0" c:root="1">
      <auth_token i:type="d:string">TestAuth</auth_token>
      <username i:type="d:string">TestUser</username>
    </LoginUser>
  </v:Body>
</v:Envelope>

respondedump

<?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>
    <LoginUserResponse xmlns="http://tempuri.org/">
      <LoginUserResult>2405</LoginUserResult>
    </LoginUserResponse>
  </soap:Body>

</soap:Envelope>

更新2
これは何 サーバーは期待しています:

<?xml version="1.0" encoding="utf-8"?>
<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>
    <LoginUser xmlns="http://tempuri.org/">
      <auth_token />
      <username />
    </LoginUser>
  </soap:Body>
</soap:Envelope>

これが何であるかです Androidアプリケーションが送信されています:

<?xml version="1.0" encoding="utf-8"?>
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"     xmlns:d="http://www.w3.org/2001/XMLSchema"  xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"     xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
    <v:Body>
        <LoginUser xmlns="http://tempuri.org" id="o0" c:root="1">
            <auth_token i:type="d:string">TestAuth</auth_token>
            <username i:type="d:string">TestUser</username>
        </LoginUser>
    </v:Body>
</v:Envelope>

これに加えて、Androidコードに次の行を追加しました。

androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

助けてください!

どうもありがとう!

役に立ちましたか?

解決

エラーをクリアすることができました...問題は、名前空間URIの後にバックスラッシュがなかったということでした。 ..しかし、今、私は異なるエラーがあります...私が助けが必要な場合、私はstackoverflowに投稿します...寛大な助けをありがとう:)

明確にするために、名前空間 しなければならない サーバーがパラメーターを受信するために、最後にAAバックスラッシュを用意します。

他のヒント

やあ
問題を解決するには2つの方法があります。1つはPropertyInfoまたは次に、パラメーターを直接追加するパラメーターを直接追加する方法です。

最初の方法:

            PropertyInfo pi = new PropertyInfo();
            pi.setName("auth_token");
            pi.setValue("TestAuth");
            pi.setType(String.class);
            request.addProperty(pi);

            PropertyInfo pe = new PropertyInfo();
            pe.setName("username");
            pe.setValue("TestUser");
            pe.setType(String.class);
            request.addProperty(pe);

2番目の方法:

    SoapObject request = new SoapObject(NAMESPACE, method_name);
    request.addProperty("auth_token","TestAuth");
    request.addProperty("username","TestUser");

このコードを試してみてください。

名前空間では、このようなキャピタルhでHTTPを書くのに役立ちます

namespaceの代わりに= "http://tempuri.org/";このnamespace = "http://tempuri.org";

少なくとも私の場合は、助けてくれました。体が役立つことを願っています!

ガブリエル

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top