모바일 응용 프로그램에서 호출되는 SQL Server 데이터베이스에 연결된 WCF 서비스가 있습니다. 나는 예약을 만드는 데 도움이되는 다음과 같은 방법을 가지고있다.WCF 게시 메서드 구현
public void CreateBooking(Booking booking)
{
Booking newbooking = new Booking();
sql = new SqlConnection("Data Source=comp;Initial Catalog=BookingDB;Integrated Security=True");
sql.Open();
string command =
("INSERT INTO Bookings(BookingName, BookingStart, BookingEnd, RoomID) " +
"VALUES ("
+ "'" + booking.BookingName + "'" + ", "
+ "'" + booking.BookingStart + "'" + ", "
+ "'" + booking.BookingEnd + "'" + ", "
+ booking.RoomID + ")");
SqlCommand cmd = new SqlCommand(command, sql);
cmd.ExecuteNonQuery();
}
public void Close()
{
sql.Close();
}
마크 업 :
<%@ ServiceHost Language="C#" Debug="true" Service="BookingServices.BookingService" CodeBehind="BookingService.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
구성 파일 :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<!--<authentication mode="None"/>-->
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<services>
<service name="RoomBookingServices.RoomBookingService" behaviorConfiguration="RoomBookingServiceBehaviour">
<endpoint address="http://192.168.0.4:6321/RoomBookingServices/RoomBookingService.svc" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="RoomBookingServices.IRoomBookingService" behaviorConfiguration="webHttpBehavior">
<identity>
<servicePrincipalName value=""/>
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RoomBookingServiceBehaviour">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true.
Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"></binding>
</webHttpBinding>
</bindings>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->
<!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />-->
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings>
<add name="RoomBookingDatabaseEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=HAL;initial catalog=RoomBookingDatabase;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="RoomBookingDatabaseEntities1" connectionString="metadata=res://*/RoomBookingDB.csdl|res://*/RoomBookingDB.ssdl|res://*/RoomBookingDB.msl;provider=System.Data.SqlClient;provider connection string="data source=HAL;initial catalog=RoomBookingDatabase;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
인터페이스 :
[OperationContract(Name="postmethod")]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, UriTemplate = "postmethod/new")]
void CreateBooking(Booking booking);
}
예약 클래스 :
그러나 내가이 메소드를 호출 할 때마다 405 오류가 발생합니다. 내 질문은 위의 오류가 발생하는 방법입니다 또는 뭔가의 연결 끝에 무엇입니까? 감사.
구성 파일과 서비스 인터페이스를 게시 할 수 있습니까? 서비스 RESTful 또는 SOAP 서비스 – Rajesh
안녕하세요 Rajesh, 기본 질문에 구성 및 인터페이스를 업로드했습니다. 감사! – moikey
예약 클래스의 스켈레톤도 문제가없는 경우 게시 할 수 있습니까? – Rajesh