SqlServer 2008 からデータを取得する Android アプリケーションがあります。
Android アプリケーションは、Sqlserver データベースにアクセスする Web サービスに接続します。データベースからデータを取得するメソッド「getCommentsTest」を呼び出してみたところ、次のエラーが発生しました。
System.Web.Services.Protocols.SoapException: サーバーは要求を処理できませんでした.---> System.Data.SqlClient.SqlException: ログインによって要求されたデータベース "my database" を開けません。ログインに失敗しました。ユーザー 'NT AUTHORITY\NETWORK SERVICE' からのログインに失敗しました。
Web サービスを公開した後、ブラウザーで Web サービスを表示しようとしたことを知り、関数を呼び出したところ、機能しました。
Web サービスを呼び出す Android コードは次のとおりです。
public void callTestGetComments() { 試す {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_GET_COMMENTS);
request.addProperty("eID", 140);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_TEST);
androidHttpTransport.call(SOAP_ACTION_GET_COMMENTS, envelope);
Object result = (Object)envelope.getResponse();
String xml=result.toString();
Document doc=XMLfromString(xml);
doc.getDocumentElement().normalize();
//System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("Comment");
//System.out.println("-----------------------");
//String commentBody,userName;
String commentBody="";
for (int i = 0; i < nList.getLength(); i++)
{
Node nNode = nList.item(i);
if (nNode.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) nNode;
//Comment c=new Comment();
commentBody += getTagValue("comment", eElement);
commentBody+= getTagValue("uPhone", eElement);
//System.out.println("Nick Name : " + getTagValue("nickname", eElement));
//System.out.println("Salary : " + getTagValue("salary", eElement));
//comments.add(c);
}
// tv.setText(result.toString());
tv.setText(commentBody);
}
}
catch (Exception e) {
tv.setText(e.getMessage());
}
}