我在服务器中使用了以下web.config的wcf服务。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="myconnection" connectionString="myconnectionstr"/>
</connectionStrings>
<system.serviceModel>
<services>
<service behaviorConfiguration="PSWebServis.PServisBehavior" name="PSWebServis.PServis">
<endpoint address="" binding="wsHttpBinding" contract="PSWebServis.IPServis" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PSWebServis.PServisBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
,这是客户端中web.config的相关部分。
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPServis" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://sunucu:8000/PServis.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IPServis" contract="PSWebServis.IPServis"
name="WSHttpBinding_IPServis">
<identity>
<servicePrincipalName value="host/SUNUCU" />
</identity>
</endpoint>
</client>
以下是我在服务中界面的一部分
[ServiceContract]
public interface IPServis
{
[OperationContract]
string InsertMusteri(MusterilerModel musteri);
}
以及服务类中的相关部分。
public class PServis : IPServis
{
public string InsertMusteri(MusterilerModel musteri)
{
if (musteri != null)
{
DataTable dtSonuc = new DataTable();
SqlCommand command = new SqlCommand("InsertMusteriModel", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@musteriTablo", musteri.KayitTablosu);
command.Parameters.AddWithValue("@telefonTablo", musteri.TelefonKayit);
command.Parameters.AddWithValue("@adresTablo", musteri.AdresKayit);
connection.Open();
command.ExecuteNonQuery();
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dtSonuc);
connection.Close();
return dtSonuc.Rows[0]["IslemDurum"].ToString();
}
return "Başarısız";
}
}
我的MusterilerModel课程:
[DataContract]
public class MusterilerModel
{
[DataMember(Order=0)]
public int MusteriID { set; get; }
[DataMember(Order = 1)]
public string Ad { set; get; }
[DataMember(Order = 2)]
public string Soyad { set; get; }
[DataMember(Order=3)]
public string KullaniciAdi { set; get; }
[DataMember(Order = 4)]
public string Email { set; get; }
[DataMember(Order = 5)]
public DateTime DogumTarihi { set; get; }
[DataMember(Order=6)]
public string GrupAdi { set; get; }
[DataMember(Order=7)]
public int Renk { set; get; }
[DataMember(Order=8)]
public decimal Bakiye { set; get; }
[DataMember(Order=9)]
public string Adres { set; get; }
[DataMember(Order=10)]
public string AdresAciklamasi { set; get; }
[DataMember(Order=11)]
public string Firma { set; get; }
[DataMember(Order=12)]
public string VergiDairesi { set; get; }
[DataMember(Order=13)]
public string VergiNo { set; get; }
[DataMember(Order=14)]
public int BayiID { set; get; }
[DataMember(Order=15)]
public string Il { set; get; }
[DataMember(Order = 16)]
public string Ilce { set; get; }
[DataMember(Order = 17)]
public decimal YemekPara { get; set; }
[DataMember(Order=18)]
public string Sifre { set; get; }
[DataMember(Order=19)]
public int GrupID { set; get; }
[DataMember(Order=20)]
public string BayiAdi { set; get; }
[DataMember(Order=21)]
public int SehirID { set; get; }
[DataMember(Order=22)]
public int IlceID { set; get; }
[DataMember(Order=23)]
public DateTime EvlilikYilDonumu { set; get; }
[DataMember(Order=24)]
public DateTime KayitTarihi { set; get; }
[DataMember(Order=25)]
public string KayitEdenPersonel { set; get; }
[DataMember(Order=26)]
public int KayitEdenPersonelID { set; get; }
[DataMember(Order=27)]
public bool AktifMi { set; get; }
[DataMember(Order=28)]
public string Aciklama { set; get; }
[DataMember(Order=29)]
public string OzelKod { set; get; }
[DataMember(Order=30)]
public int SatisID { set; get; }
[DataMember(Order=31)]
public DataTable KayitTablosu { set; get; }
[DataMember(Order=32)]
public DataTable TelefonKayit { set; get; }
[DataMember(Order=33)]
public DataTable AdresKayit { set; get; }
}
当我尝试使用InsertMusteri方法时,数据库中有2条记录。如您所见,我将我的信息放入datatable并将其发送到服务。我检查过,如果datatable有超过1个值,但这不是问题。我不知道问题出在哪里。
答案 0 :(得分:2)
评论此行
command.ExecuteNonQuery();
检查它是否正常工作。 我认为“填充”命令会执行你的命令。