2017-03-08 16 views
0

SQL Server Management Studio Express(無料版)を使用してDB、Visual Studio Community(無料版)を作成してASP.netを通じてWebサービスSOAPを作成しました(WSは、それをクリックすると1つのWebメソッドしか持たず、空のフィールドを5つ表示します)、その後、ソリューション設定メニューのオプションDebugを使用してWSでVSを実行した後、ページを開いて、私のDBには、ここまではすべて正しいものでしたが、データは適切な列に挿入されました。Webサービスに接続できませんHTTPリクエストが失敗しましたerr400

私の問題は、アンドロイドアプリを作成するときに、ユーザーが記入してWSに情報を送信してDBにデータを送信するが、次のエラーを表示する空のフィールドが5つある:
org.ksoap2.transport.HttpResponseException:HTTP要求が失敗し、HTTPステータス:400
でorg.ksoap2.transport.HttpTransportSE.call

私はこの問題について、すべてのスレッドを読みますが、その情報のどれも私の問題を解決しません私は3つの異なるバリエーションを持つ別のプロジェクトを作ろうとしましたが、どれも動作しませんでした。ローカルIPをローカルホストに変更しました。10.0.2.2:portを使用してください。最後に "?ws dl "など。

WSUIをテストするためにSOAPUIを使用しましたが、どこの場所からでも接続しようとすると、ページが見つかりませんでした。それから、私は、WSが私のためだけに、他の誰のためにも働かないので、私のアプリケーションが動作しないかもしれないことに気付き、私のWSを実際のドメインに置く必要があります。

私はこの世界で非常にnoobですが、実際の目的は、私のアプリがインターネット上のデータベースにデータを取得/追加することができるということです。この方法がその目標に合っているかどうかは分かりません。

私は3日以上前から情報を探しています。私はこれを解決できません。

ありがとうございます!

私のアンドロイドのコードは以下の通りです:

package com.example.ejembd2; 

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapPrimitive; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE; 


import android.os.AsyncTask; 
import android.os.Bundle; 
import android.app.Activity; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 


public class MainActivity extends Activity { 


private TextView txtResultado; 
private Button btnins; 
private EditText txtTit; 
private EditText txtDes; 
private EditText txtAco; 
private EditText txtPal; 
private EditText txtFec; 
private TextView txtResultado2; 




@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    txtCodigo = (EditText) findViewById(R.id.txtReg); 
    txtNombre = (EditText) findViewById(R.id.txtVal); 
    txtResultado = (TextView) findViewById(R.id.txtResultado); 

    btnInsertar = (Button) findViewById(R.id.btnInsertar); 
    btnActualizar = (Button) findViewById(R.id.btnActualizar); 
    btnEliminar = (Button) findViewById(R.id.btnEliminar); 
    btnConsultar = (Button) findViewById(R.id.btnConsultar); 

    btnins = (Button) findViewById(R.id.InsEnBD); 
    txtTit = (EditText) findViewById(R.id.T); 
    txtDes = (EditText) findViewById(R.id.D); 
    txtAco = (EditText) findViewById(R.id.A); 
    txtPal = (EditText) findViewById(R.id.P); 
    txtFec = (EditText) findViewById(R.id.F); 
    txtResultado2 = (TextView) findViewById(R.id.txtResultado2); 

    btnins.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      String a = txtTit.getText().toString(); 
      String b = txtDes.getText().toString(); 
      String c = txtAco.getText().toString(); 
      String d = txtPal.getText().toString(); 
      String f = txtFec.getText().toString(); 
      new insercion1().execute(a, b, c, d, f); 
     } 
    }); 
} 



private class insercion1 extends AsyncTask<String,Integer,Boolean> { 


    @Override 
    protected Boolean doInBackground(String... params) { 

     String a = params[0]; 
     String b = params[1]; 
     String c = params[2]; 
     String d = params[3]; 
     String f = params[4]; 

    boolean resul = true; 

    final String NAMESPACE = "http://proof.net/"; 
    /*final String URL = "http://10.0.2.2:50490/ServicioWebSoap/ServicioClientes.asmx"; //cambio*/ 
     final String URL = "http://10.0.2.2:50490/ServicioClientes.asmx"; 
    final String METHOD_NAME = "NuevoEvento"; 
    final String SOAP_ACTION = "http://proof.net/NuevoEvento"; 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    request.addProperty("Titulo",a); 
    request.addProperty("Descripcion",b); 
    request.addProperty("Compania",c); 
    request.addProperty("Palabras",d); 
    request.addProperty("Fecha",f); 

    SoapSerializationEnvelope envelope = 
      new SoapSerializationEnvelope(SoapEnvelope.VER11); 

    envelope.dotNet=true; 

    envelope.setOutputSoapObject(request); 


    HttpTransportSE transporte = new HttpTransportSE(URL); 

    try 

    { 
     transporte.call(SOAP_ACTION, envelope); 
     Log.v("prueba1", ">>>>>>>>>"); 

     SoapPrimitive resultado_xml = (SoapPrimitive) envelope.getResponse(); 
     String res = resultado_xml.toString(); 
     //My code in the .asmx return 1 if a row was added to the Table. 

     if (!res.equals("1")) 
      resul = false; 
    } 

    catch(
    Exception e 
    ) 

    { 
     e.printStackTrace(); 
     resul = false; 
    } 

    return resul; 
    } 

    protected void onPostExecute(Boolean result) { 


     if (result) 
      txtResultado.setText("Insertado OK"); 
     else 
      txtResultado.setText("Error!"); 
    } 
} 
} 

EDIT1:WSDL(イムのみWebMethodの "NuevoEvento" を使用して)

<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://proof.net/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://proof.net/"> 
<wsdl:types> 
<s:schema elementFormDefault="qualified" targetNamespace="http://proof.net/"> 
<s:element name="NuevoEvento"> 
<s:complexType> 
<s:sequence> 
<s:element minOccurs="0" maxOccurs="1" name="Titulo" type="s:string"/> 
<s:element minOccurs="0" maxOccurs="1" name="Descripcion" type="s:string"/> 
<s:element minOccurs="0" maxOccurs="1" name="Compania" type="s:string"/> 
<s:element minOccurs="0" maxOccurs="1" name="Palabras" type="s:string"/> 
<s:element minOccurs="0" maxOccurs="1" name="Fecha" type="s:string"/> 
</s:sequence> 
</s:complexType> 
</s:element> 
<s:element name="NuevoEventoResponse"> 
<s:complexType> 
<s:sequence> 
<s:element minOccurs="1" maxOccurs="1" name="NuevoEventoResult" type="s:int"/> 
</s:sequence> 
</s:complexType> 
</s:element> 
<s:element name="ListadoEventos"> 
<s:complexType/> 
</s:element> 
<s:element name="ListadoEventosResponse"> 
<s:complexType> 
<s:sequence> 
<s:element minOccurs="0" maxOccurs="1" name="ListadoEventosResult" type="tns:ArrayOfEventos"/> 
</s:sequence> 
</s:complexType> 
</s:element> 
<s:complexType name="ArrayOfEventos"> 
<s:sequence> 
<s:element minOccurs="0" maxOccurs="unbounded" name="Eventos" nillable="true" type="tns:Eventos"/> 
</s:sequence> 
</s:complexType> 
<s:complexType name="Eventos"> 
<s:sequence> 
<s:element minOccurs="1" maxOccurs="1" name="Id" type="s:int"/> 
<s:element minOccurs="0" maxOccurs="1" name="Titulo" type="s:string"/> 
<s:element minOccurs="0" maxOccurs="1" name="Descripcion" type="s:string"/> 
<s:element minOccurs="0" maxOccurs="1" name="Compania" type="s:string"/> 
<s:element minOccurs="0" maxOccurs="1" name="Palabras" type="s:string"/> 
<s:element minOccurs="0" maxOccurs="1" name="Fecha" type="s:string"/> 
</s:sequence> 
</s:complexType> 
<s:element name="NuevoEventoObjeto"> 
<s:complexType> 
<s:sequence> 
<s:element minOccurs="0" maxOccurs="1" name="evento" type="tns:Eventos"/> 
</s:sequence> 
</s:complexType> 
</s:element> 
<s:element name="NuevoEventoObjetoResponse"> 
<s:complexType> 
<s:sequence> 
<s:element minOccurs="1" maxOccurs="1" name="NuevoEventoObjetoResult" type="s:int"/> 
</s:sequence> 
</s:complexType> 
</s:element> 
</s:schema> 
</wsdl:types> 
<wsdl:message name="NuevoEventoSoapIn"> 
<wsdl:part name="parameters" element="tns:NuevoEvento"/> 
</wsdl:message> 
<wsdl:message name="NuevoEventoSoapOut"> 
<wsdl:part name="parameters" element="tns:NuevoEventoResponse"/> 
</wsdl:message> 
<wsdl:message name="ListadoEventosSoapIn"> 
<wsdl:part name="parameters" element="tns:ListadoEventos"/> 
</wsdl:message> 
<wsdl:message name="ListadoEventosSoapOut"> 
<wsdl:part name="parameters" element="tns:ListadoEventosResponse"/> 
</wsdl:message> 
<wsdl:message name="NuevoEventoObjetoSoapIn"> 
<wsdl:part name="parameters" element="tns:NuevoEventoObjeto"/> 
</wsdl:message> 
<wsdl:message name="NuevoEventoObjetoSoapOut"> 
<wsdl:part name="parameters" element="tns:NuevoEventoObjetoResponse"/> 
</wsdl:message> 
<wsdl:portType name="ServicioClientesSoap"> 
<wsdl:operation name="NuevoEvento"> 
<wsdl:input message="tns:NuevoEventoSoapIn"/> 
<wsdl:output message="tns:NuevoEventoSoapOut"/> 
</wsdl:operation> 
<wsdl:operation name="ListadoEventos"> 
<wsdl:input message="tns:ListadoEventosSoapIn"/> 
<wsdl:output message="tns:ListadoEventosSoapOut"/> 
</wsdl:operation> 
<wsdl:operation name="NuevoEventoObjeto"> 
<wsdl:input message="tns:NuevoEventoObjetoSoapIn"/> 
<wsdl:output message="tns:NuevoEventoObjetoSoapOut"/> 
</wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="ServicioClientesSoap" type="tns:ServicioClientesSoap"> 
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="NuevoEvento"> 
<soap:operation soapAction="http://proof.net/NuevoEvento" style="document"/> 
<wsdl:input> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
<wsdl:operation name="ListadoEventos"> 
<soap:operation soapAction="http://proof.net/ListadoEventos" style="document"/> 
<wsdl:input> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
<wsdl:operation name="NuevoEventoObjeto"> 
<soap:operation soapAction="http://proof.net/NuevoEventoObjeto" style="document"/> 
<wsdl:input> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:binding name="ServicioClientesSoap12" type="tns:ServicioClientesSoap"> 
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="NuevoEvento"> 
<soap12:operation soapAction="http://proof.net/NuevoEvento" style="document"/> 
<wsdl:input> 
<soap12:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap12:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
<wsdl:operation name="ListadoEventos"> 
<soap12:operation soapAction="http://proof.net/ListadoEventos" style="document"/> 
<wsdl:input> 
<soap12:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap12:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
<wsdl:operation name="NuevoEventoObjeto"> 
<soap12:operation soapAction="http://proof.net/NuevoEventoObjeto" style="document"/> 
<wsdl:input> 
<soap12:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap12:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="ServicioClientes"> 
<wsdl:port name="ServicioClientesSoap" binding="tns:ServicioClientesSoap"> 
<soap:address location="http://localhost:50490/ServicioClientes.asmx"/> 
</wsdl:port> 
<wsdl:port name="ServicioClientesSoap12" binding="tns:ServicioClientesSoap12"> 
<soap12:address location="http://localhost:50490/ServicioClientes.asmx"/> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

EDIT1:私はサービスにポストされたデータ(最初のWebメソッドのみを使用)

using System.Collections.Generic; 
using System.Data.SqlClient; 
using System.Web.Services; 

namespace ServicioWebSoap 
{ 
/// <summary> 
/// Descripción breve de ServicioClientes 
/// </summary> 
[WebService(Namespace = "http://proof.net/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.ComponentModel.ToolboxItem(false)] 
// Para permitir que se llame a este servicio web desde un script, usando  ASP.NET AJAX, quite la marca de comentario de la línea siguiente. 
// [System.Web.Script.Services.ScriptService] 
public class ServicioClientes : System.Web.Services.WebService 
{ 
    [WebMethod] 
    public int NuevoEvento(string Titulo, string Descripcion, string Compania, string Palabras, string Fecha) 
    { 
     SqlConnection con = new SqlConnection(@"Data Source=SRCOMPUTADOR\SQLEXPRESS01;Initial Catalog=DBEventos;Integrated Security=True"); 

     con.Open(); 

     string sql = "INSERT INTO Eventos (Titulo, Descripcion, Compania, Palabras, Fecha) VALUES (@Titulo, @Descripcion, @Compania, @Palabras, @Fecha)"; 

     SqlCommand cmd = new SqlCommand(sql, con); 

     cmd.Parameters.Add("@Titulo", System.Data.SqlDbType.NVarChar).Value = Titulo; 
     cmd.Parameters.Add("@Descripcion", System.Data.SqlDbType.NVarChar).Value = Descripcion; 
     cmd.Parameters.Add("@Compania", System.Data.SqlDbType.NVarChar).Value = Compania; 
     cmd.Parameters.Add("@Palabras", System.Data.SqlDbType.NVarChar).Value = Palabras; 
     cmd.Parameters.Add("@Fecha", System.Data.SqlDbType.NVarChar).Value = Fecha; 

     int res = cmd.ExecuteNonQuery(); 

     con.Close(); 

     return res; 
    } 

    [WebMethod] 
    public Eventos[] ListadoEventos() 
    { 
     SqlConnection con = new SqlConnection(@"Data Source=SRCOMPUTADOR\SQLEXPRESS01;Initial Catalog=DBEventos;Integrated Security=True"); 

     con.Open(); 

     string sql = "SELECT id, Titulo, Descripcion, Compania, Palabras, Fecha FROM Eventos"; 

     SqlCommand cmd = new SqlCommand(sql, con); 

     SqlDataReader reader = cmd.ExecuteReader(); 

     List<Eventos> lista = new List<Eventos>(); 

     while (reader.Read()) 
     { 
      lista.Add(
       new Eventos(reader.GetInt32(0), 
          reader.GetString(1), 
          reader.GetString(2), 
          reader.GetString(3), 
          reader.GetString(4), 
          reader.GetString(5))); 
     } 

     con.Close(); 

     return lista.ToArray(); 
    } 

    [WebMethod] 
    public int NuevoEventoObjeto(Eventos evento) 
    { 
     SqlConnection con = new SqlConnection(@"Data Source=SRCOMPUTADOR\SQLEXPRESS01;Initial Catalog=DBEventos;Integrated Security=True"); 

     con.Open(); 

     string sql = "INSERT INTO Eventos (Titulo, Descripcion, Compania, Palabras, Fecha) VALUES (@Titulo, @Descripcion, @Compania, @Palabras, @Fecha)"; 

     SqlCommand cmd = new SqlCommand(sql, con); 

     cmd.Parameters.Add("@Titulo", System.Data.SqlDbType.NVarChar).Value = evento.Titulo; 
     cmd.Parameters.Add("@Descripcion", System.Data.SqlDbType.NVarChar).Value = evento.Descripcion; 
     cmd.Parameters.Add("@Compania", System.Data.SqlDbType.NVarChar).Value = evento.Compania; 
     cmd.Parameters.Add("@Palabras", System.Data.SqlDbType.NVarChar).Value = evento.Palabras; 
     cmd.Parameters.Add("@Fecha", System.Data.SqlDbType.NVarChar).Value = evento.Fecha; 

     int res = cmd.ExecuteNonQuery(); 

     con.Close(); 

     return res; 
    } 
} 

}

+0

400は悪いリクエストを意味します - 私たちにwsdlを表示し、サービスに投稿したデータを表示します。 – csmckelvey

+0

あなたが@takendarkkをリクエストした情報はありますが、VSにコードを入力するときに「あなたがサービスに投稿したデータ」を置いたときにコードを尋ねていたのかどうかはわかりません。 – Erick

答えて

0

回答は私の訴訟でした。 WSはエミュレーション(Webには存在しません)でしたが、次の手順で解決されました。

  1. これをVSで公開し、IISマネージャを使用します。
  2. WSで問題が発生した場合は、support.microsoft.comが実際に提供する指示(私は数日前に検索し、そのキーはそこにありました)に従ってください。
  3. 次に、HttpTransportSEコールのURLに、ローカルホストを "localhost"に置き換えて使用します。
関連する問題