MicrosoftAzureでASMXWebサービスをセットアップしていて、Androidアプリケーションを使用してWebサービスにデータを送信し、出力を受信しようとしています。この目的のために、私はKSOAPライブラリを使用しています。
Webサービスで、文字列が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);
名前空間、メソッド名、URLなどを提供できて申し訳ありません。これは会社のポリシーに違反しているため、ご理解いただければ幸いです。:)
それでも、エラーをもう一度確認します。上記のAndroidコードを呼び出した後、Webサービスは2405を返します。これは、ASMXコードによると、2つの値のいずれかがnullの場合です。
更新: SOAPリクエスト(androidHttpTransport.debug = true)をデバッグし、requestDumpとresponseDumpに対して次の結果を取得しました。
ダンプをリクエスト
<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>
responseDump
<?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>
UPDATE2
これはサーバーが期待するものです。
<?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\"?>");
助けてください!
どうもありがとう!