我确实使用了SQL Server Management Studio Express(免费版)来创建我的DB,Visual Studio Community(Free Edition),以通过ASP.NET创建Web服务肥皂(WS只有WS1个Web方法单击它时,然后显示5个空字段),然后我在"解决方案配置"菜单中的选项调试中运行了WS,此后页面打开了,我确实检查了我的方法在DB中插入数据,直到直到直到这里的一切都是正确的,数据已插入正确的列中。
我的问题开始时,当我构建Android应用程序时,该应用具有5个空字段,用户将填充该信息,然后将信息发送到WS并将数据发送到DB中,但请向我展示下一个错误:
org.ksoap2.transport.httpresponseexception:HTTP请求失败,HTTP状态:400
atorg.ksoap2.transport.httptransportse.call
我阅读了有关此问题的每个线程,但是这些信息都无法解决我的问题,我试图制作一个具有3种不同变体的项目,但它们都无法正常工作,我更改了本地IP的localhost,使用10.0.2.2:端口,我在最后添加"?WSDL"等,等等。
我使用SOAPUI连接以测试我的WS,但是当我尝试从所说的任何位置连接到我的任何位置时都找不到页面。然后我意识到我的应用程序也许不起作用,因为WS仅对我和其他人有用,需要将我的WS放在真实的领域或类似的范围内。
我在这个世界上非常菜鸟,但是我拥有的真正目标是我的应用程序可以在Internet上的数据库中获取/添加数据,以便用户可以看到/添加数据,我不知道这种方式是否正确。
欢迎任何建议,请从3天前开始搜索信息,我无法解决。
预先感谢!
我的Android代码如下:
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:我发布到服务的数据(仅使用第一个WebMethod)
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=SRCOMPUTADORSQLEXPRESS01;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=SRCOMPUTADORSQLEXPRESS01;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=SRCOMPUTADORSQLEXPRESS01;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;
}
}
}
答案是我的suposition;WS仅是仿真(网络中不存在),该解决方案是按照下一步解决的:
:- 使用VS发布并使用IIS经理。
- 如果WS出现问题,请按照支持的说明。Microsoft.com交付确实有效(我搜索了几天,关键在那里)。
- 然后在httptransportse呼叫的URL中使用您的本地IP代替" localhost"。